JunkBox_Lib  1.10.2
tools.h File Reference

汎用ツールヘッダ More...

#include "common.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <stdarg.h>
#include <ctype.h>
#include <unistd.h>
#include <sys/sysinfo.h>
#include <errno.h>
#include <signal.h>
Include dependency graph for tools.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

union  unionVal
 
union  unionPtr
 
struct  ringBuffer
 
struct  rectAngle
 

Macros

#define CHAR_CR   0x0d
 改行 More...
 
#define CHAR_LF   0x0a
 ラインフィード More...
 
#define CHAR_TAB   0x09
 タブ More...
 
#define CODE_US   0
 
#define CODE_EN   0
 
#define CODE_EUC   1
 
#define CODE_SJIS   2
 
#define CODE_UTF8   3
 
#define UNKNOWN_ENDIAN   0
 
#define LITTLE_ENDIAN   1234
 
#define BIG_ENDIAN   4321
 
#define PDP_ENDIAN   3412
 
#define CHAR_DELI_DIR   '/'
 
#define STR_DELI_DIR   "/"
 
#define STR_CRNT_DIR   "./"
 
#define STR_UPST_DIR   "../"
 
#define mstream   ringBuffer
 バイト型 メッセージストリーム More...
 
#define LOCAL_IPv4   "127.0.0.1"
 
#define LOCAL_IPv6   "::1"
 
#define LOCAL_IPADDR   LOCAL_IPv4
 
#define LOCAL_IPADDR6   LOCAL_IPv6
 
#define freeNull(p)   {if(!isNull((void*)p)) free(p); (p)=NULL;}
 
#define freenull(p)   {if(!isNull((void*)p)) free(p); (p)=NULL;}
 
#define free_null(p)   freeNull((p))
 
#define _tochar(a)   (char*)(a)
 
#define dup_string(s)   dup_str((s))
 dup_str() More...
 
#define pack_char(s, c)   pack_char_len((s), (c), -1)
 pack_char_len() More...
 
#define htonull(s)   ntohull((s))
 Host形式からNetwork形式へ,64bit long unsigned long int データの変換 ntohull() More...
 
#define int_swap(p, s)   {int swap=(p); (p)=(s); (s)=swap;}
 データを入れ替える More...
 
#define ex_strcmp(a, b)   ex_strncasecmp((a), (b), -1)
 文字列 aの長さに合わせて比較する.大文字小文字を区別しない.一致するなら TRUE More...
 
#define print_hex(o, m, n)   fdump((o), (m), (n))
 
#define random_str(n)   temp_filename(NULL, (n))
 ランダムな文字列を生成.要 free(). see temp_filename() More...
 
#define init_mstream()   init_ringBuffer()
 init_ringBuffer() More...
 
#define new_mstream(s)   new_ringBuffer((s))
 new_ringBuffer() More...
 
#define make_mstream(s)   make_ringBuffer((s))
 make_ringBuffer() More...
 
#define free_mstream(s)   free_ringBuffer((s))
 free_ringBuffer() More...
 
#define del_mstream(s)   del_ringBuffer((s))
 del_ringBuffer() More...
 
#define clear_mstream(s)   clear_ringBuffer((s))
 clear_ringBuffer() More...
 
#define set_sigseg_handler(h)   set_sigsegv_handler((h))
 set_sigsegv_handler() More...
 
#define copy_file(src, dst)   file_from_to((src), (dst), "wb")
 srcから dstへファイルをコピーする.file_from_to() More...
 
#define cat_file(src, dst)   file_from_to((src), (dst), "ab")
 srcから dstへファイルを catする. file_from_to() More...
 
#define isBigEndian   (is_big_endian())
 
#define isLittleEndian   (is_little_endian())
 
#define ntoh_st(p, s)   {if(!isBigEndian) swap_byte((void*)(p),sizeof(*(p)),(s));}
 network形式から host形式へ.構造体pに対して sバイトづつ変換. More...
 
#define hton_st(p, s)   {if(!isBigEndian) swap_byte((void*)(p),sizeof(*(p)),(s));}
 host形式から network形式へ.構造体pに対して sバイトづつ変換. More...
 
#define ntoh_ar(p, s)   {if(!isBigEndian) swap_byte((void*)(p),(s),sizeof(*(p)));}
 network形式から host形式へ.長さsバイトの配列pに対して変換 More...
 
#define hton_ar(p, s)   {if(!isBigEndian) swap_byte((void*)(p),(s),sizeof(*(p)));}
 host形式から network形式へ.長さsバイトの配列pに対して変換. More...
 
#define ntoh_data(p, s, c)   {if(!isBigEndian) swap_byte((void*)(p),(s),(c));}
 network形式からhost形式へ. cバイトづつ変換する. More...
 
#define hton_data(p, s, c)   {if(!isBigEndian) swap_byte((void*)(p),(s),(c));}
 host形式から network形式へ. cバイトづつ変換する. More...
 
#define JBXL_LOG_FILE   "/var/log/jbxl.log"
 デフォルトのログファイル More...
 
#define JBXL_ERR_FILE   "/var/log/jbxl.err"
 デフォルトのエラーファイル More...
 
#define PRINT_MESG   print_message
 環境依存用の出力関数.print_message() More...
 
#define PRINT_ESC   print_escape
 環境依存用の出力関数.print_escape() More...
 
#define PRINT_INFO   print_message
 環境依存用の出力関数.print_message() More...
 
#define PRINT_WARN   print_message
 環境依存用の出力関数.print_message() More...
 
#define PRINT_ERROR   print_message
 環境依存用の出力関数.print_message() More...
 
#define EBUG
 
#define DEBUG_MODE   if(DebugMode==ON)
 
#define NO_DEBUG_MODE   if(DebugMode==OFF)
 
#define DEBUG_INFO   PRINT_INFO
 デバッグ用出力関数.コンパイル時に削除可能 More...
 
#define DEBUG_WARN   PRINT_WARN
 デバッグ用出力関数.コンパイル時に削除可能 More...
 
#define DEBUG_ERROR   PRINT_ERROR
 デバッグ用出力関数.コンパイル時に削除可能 More...
 
#define DEBUG_MESG   PRINT_MESG
 デバッグ用出力関数.コンパイル時に削除可能 More...
 

Functions

int isNull (void *p)
 
char * get_line (char *buf, int n)
 文字型データbufのバッファ内の n行目を取り出す.改行コードは削除される.要 free() More...
 
char * get_seq_data (char *buf, int *ptr)
 文字型データbufのバッファ内の 行データをシーケンシャルに取り出す. More...
 
char * awk (char *str, char cc, int n)
 ccを区切り記号として, strのバッファ内の n番目の項目を返す.要 free() More...
 
char * cawk (char *str, char cc, int n)
 連続するccを区切り記号として, strのバッファ内の n番目の項目を返す.要 free() More...
 
void replace_char (unsigned char *buf, int len, unsigned char frm, unsigned char toc)
 データbuf 中のバイトデータ frm を tocに変更する. More...
 
char * replace_str (char *buf, int len, const char *frm, const char *tos)
 文字列 buf中の frmを tosに書き換えたものを返す.free() してはいけない.
More...
 
char * cut_str (char *buf, int ls, int le)
 buf[ls]〜buf[le] を切り出す.要 free() More...
 
char * dup_str (char *buf)
 文字列を複製する.要 free() More...
 
char * skip_chars (char *pp, const char *check)
 check[]中の何れかの文字までポインタをスキップさせる.ただし クォーテーション内は完全スキップ More...
 
char * skip_char (char *pp, char cc)
 cc の文字までポインタをスキップさせる.ただし クォーテーション内は完全スキップ More...
 
char * skip_char_pair (char *pp, char pair, char end)
 pair と end で閉じるまでポインタをスキップさせる.ただし クォーテーション内は完全スキップ More...
 
char * skip_string_end (char *pp)
 次の文字列を一つスキップする.最期のクォーテーションの位置を返す. More...
 
char * pack_char_len (char *pp, char cc, int len)
 文字列の一部の先頭のcc(複数),終わりのcc(複数),CR, LF を削除.要 free() More...
 
char * pack_head_tail_char (char *pp, char cc)
 文字の先頭のcc(複数),TAB, CR, LF.終わりのcc(複数),TAB, CR, LF を削除.要 free() More...
 
char * change_esc (char *pp)
 文字列中の CR, LF を \r, \n に変換する.要 free() More...
 
char * chomp (char *str)
 最初の改行コード以降を無効にする. More...
 
char * double_bs (char *fn)
 文字列中の \ を \\に置き換えた文字列を返す.要 free() More...
 
char * numbering_name (const char *fmt, int n)
 フォーマット fmtに従って,nを含む文字列を作り出す.要 free() More...
 
int is_number (unsigned char *)
 数字かどうか判定する(簡易版).整数(1) と小数点付き数字(2) のみ. More...
 
char * itostr (int n)
 int を文字に変換する.free() は不要
More...
 
char * ltostr (long int n)
 long int を文字に変換する.free() は不要
More...
 
char * ultostr (long unsigned int n)
 long unsigned int を文字に変換する.free() は不要
More...
 
char * lltostr (long long int n)
 long long int を文字に変換する.free() は不要
More...
 
char * ulltostr (long unsigned long int n)
 long unsigned long int を文字に変換する.free() は不要
More...
 
char * ftostr (float n)
 float を文字に変換する.free() は不要
More...
 
char * dtostr (double n)
 double を文字に変換する.free() は不要
More...
 
char * itostr_ts (int n)
 int を文字に変換する.要 free()
More...
 
char * ltostr_ts (long int n)
 long int を文字に変換する.要 free()
More...
 
char * ultostr_ts (long unsigned int n)
 long unsigned int を文字に変換する.要 free()
More...
 
char * lltostr_ts (long long int n)
 long long int を文字に変換する.要 free() More...
 
char * ulltostr_ts (long unsigned long int n)
 long unsigned long int を文字に変換する.要 free() More...
 
char * ftostr_ts (float n)
 float を文字に変換する.要 free() More...
 
char * dtostr_ts (double n)
 double を文字に変換する.要 free() More...
 
int count_lines (const char *buf)
 文字列データの行数を数える.行頭が '\0'の場合も1行と数える. More...
 
int hexstr2i (const char *str)
 16進の文字列を整数に変換する. More...
 
long unsigned long int ntohull (long unsigned long int s)
 Network形式からHost形式へ,64bit long unsigned long int データの変換 More...
 
void swap_byte (void *p, int s, int b)
 sの長さのpのバイト順序をbバイト毎に逆順にする. More...
 
short swaps (unsigned short p)
 16bit の上下8bitを入れ替える. More...
 
int swapl (unsigned int p)
 32bit pを8bitづつ逆順にする More...
 
long long int swapd (long unsigned long int p)
 64bit pを8bitづつ逆順にする More...
 
void reverse_str (uByte *p, int s)
 バイト(octet)列を逆順にする. More...
 
void upper_string (char *str)
 
int bincmp (unsigned char *b1, unsigned char *b2, int n)
 バイナリデータを n Byte比べる.一致するなら 0 More...
 
int strnrvscmp (const char *s1, const char *s2, int n)
 文字列 s1と s2を後ろから n文字比較する.一致するなら 0 More...
 
int strncaservscmp (const char *s1, const char *s2, int n)
 文字列 s1と s2を後ろから n文字比較する.大文字小文字は区別しない.一致するなら 0 More...
 
char * strstrcase (const char *buf, const char *nd)
 文字列 bufの中に文字列 ndがあるかどうかをチェックする.大文字小文字は区別しない. More...
 
int ex_strncmp (const char *s1, const char *s2, int n)
 文字列 s1とs2を拡張比較する.一致するなら TRUE More...
 
int ex_strncasecmp (const char *s1, const char *s2, int n)
 文字列 s1とs2を拡張比較する.大文字小文字を区別しない.一致するなら TRUE More...
 
int ex_strnrvscmp (const char *s1, const char *s2, int n)
 文字列 s1とs2を後ろから拡張比較する.一致するなら TRUE More...
 
int ex_strncaservscmp (const char *s1, const char *s2, int n)
 文字列 s1とs2を後ろから拡張比較する.一致するなら TRUE More...
 
int is_little_endian (void)
 エンディアンの動的チェック More...
 
int is_big_endian (void)
 エンディアンの動的チェック More...
 
void check_endian (void)
 システムのエンディアンを判別して,大域変数 HostEndian に設定する More...
 
double double_from_little_endian (void *ptr)
 エンディアンによるデータ変換 More...
 
float float_from_little_endian (void *ptr)
 
int int_from_little_endian (void *ptr)
 
unsigned int uint_from_little_endian (void *ptr)
 
short short_from_little_endian (void *ptr)
 
unsigned short ushort_from_little_endian (void *ptr)
 
double double_from_big_endian (void *ptr)
 
float float_from_big_endian (void *ptr)
 
int int_from_big_endian (void *ptr)
 
unsigned int uint_from_big_endian (void *ptr)
 
short short_from_big_endian (void *ptr)
 
unsigned short ushort_from_big_endian (void *ptr)
 
char * get_local_timestamp (time_t date, const char *format)
 要 free() More...
 
char * get_gmt_timestamp (time_t date, const char *format)
 要 free() More...
 
void print_escape (const char *format, char *mesg)
 エスケープ文字を含むメッセージの出力(stderr) More...
 
void fdump (FILE *fp, unsigned char *mesg, int n)
 16進ダンプを吐き出す More...
 
void print_16x (FILE *fp, unsigned char *mesg, int n)
 16進ダンプを吐き出す(1行) More...
 
char * get_graphic_extension (uWord tex)
 
void kanji_convert (unsigned char *mesg)
 大域変数 KnjiCodeに従って漢字コードを変換する. More...
 
void kanji_convert_euc2sjis (unsigned char *mesg)
 EUCをSJISに変換する. More...
 
void kanji_convert_sjis2euc (unsigned char *mesg)
 SJISをEUCに変換する. More...
 
void euc2sjis (unsigned char *c1, unsigned char *c2)
 EUC -> SJIS. More...
 
void sjis2euc (unsigned char *c1, unsigned char *c2)
 SJIS -> EUC. More...
 
int file_from_to (const char *s, const char *d, const char *mode)
 modeに従って,ファイル sを dにコピーする. More...
 
int fp_from_to (FILE *s, FILE *d, long int sz)
 ファイル sを dにコピーする. More...
 
char * get_file_name (const char *str)
 フルパスからファイル名へのポインタを取り出す.free() してはいけない. More...
 
char * get_file_extension (const char *str)
 フルパスからファイル名の拡張子へのポインタを取り出す.free() してはいけない. More...
 
char * del_file_name (const char *str)
 フルパスを書き換えてファイル名部分を削除する.free() してはいけない. More...
 
char * del_file_extension (const char *str)
 フルパスを書き換えて拡張子を削除する.free() してはいけない. More...
 
char * get_file_path (const char *str)
 ファイル名を含むパスからパスのみを生成する.strは変化しない.要 free(). More...
 
char * cut_file_extension (const char *str)
 拡張子を削除したフパス名を生成する.strは変化しない.要 free(). More...
 
long unsigned file_size (const char *fn)
 ファイルの大きさを返す. More...
 
int file_exist (const char *fn)
 ファイルの存在を検査する. More...
 
FILE * file_chmod_open (const char *fn, const char *fm, mode_t mode)
 ファイルの許可属性をmode へ変更した後,ファイルを fmモードでオープン More...
 
char * temp_filename (const char *, int)
 /dev/urandom を利用して作業用ファイルのランダムなファイル名を得る. More...
 
unsigned char * read_file (const char *fname, long unsigned int *size)
 ファイルからデータを読み込む More...
 
long unsigned int write_file (const char *fname, unsigned char *buf, long unsigned int size)
 ファイルにデータを書き込む More...
 
int mkdirp (const char *path, mode_t mode)
 mkdir -p path 相当. More...
 
void init_rand (void)
 /dev/urandom からデータで乱数の系列を初期化する More...
 
char * randstr (int n)
 ランダムに A-Za-z0-9 までの文字を n文字生成する. More...
 
unsigned char * randbit (int n)
 ランダムに n bitのバイナリを生成する. More...
 
unsigned char * encode_base64 (unsigned char *str, int sz)
 バイナリデータ bufを base64にエンコードする.要 free() More...
 
unsigned char * decode_base64 (unsigned char *str, int *sz)
 bufを base64からデコードする.要 free() More...
 
unsigned char * encode_base64_filename (unsigned char *str, int sz, unsigned char cc)
 バイナリデータ bufを Base64で encodeしてファイル名を作る.ただし '/' は cc として扱う.要 free() More...
 
unsigned char * decode_base64_filename (unsigned char *str, int *sz, unsigned char cc)
 bufを Base64で decodeしてバイナリデータを取り出す.ただし cc は '/' として扱う.要 free() More...
 
unsigned char * encode_urlenc (unsigned char *str, int sz)
 バイナリデータ bufを URLエンコードする.要 free() More...
 
unsigned char * decode_urlenc (unsigned char *str, int *sz)
 buf を URLエンコードからデコードする.要 free() More...
 
unsigned char * encode_quoted_printable (unsigned char *str, int sz)
 バイナリデータ bufを quoted printable にエンコードする.要 free() More...
 
unsigned char * decode_quoted_printable (unsigned char *str, int *sz)
 buf を quoted printableからデコードする.要 free() More...
 
unsigned char * encode_hex (unsigned char cc)
 キャラクタを16進コードの文字列に変換する.要 free() More...
 
unsigned char decode_hex (unsigned char c1, unsigned char c2)
 16進コードをキャラクタに変換する.O-9,A-F以外が指定された場合は0とみなす. 内容を書き換える. More...
 
ringBuffernew_ringBuffer (int sz)
 リングバッファを生成する. More...
 
ringBuffer init_ringBuffer (void)
 リングバッファを初期化する. More...
 
ringBuffer make_ringBuffer (int sz)
 バッファ部が存在するリングバッファを作り出す. More...
 
void del_ringBuffer (ringBuffer **pp)
 リングバッファそのものを削除する.new_ringBuffer() と対. More...
 
void free_ringBuffer (ringBuffer *pp)
 リングバッファを解放する.make_ringBuffer() と対. More...
 
void clear_ringBuffer (ringBuffer *pp)
 リングバッファのデータを削除する. More...
 
int put_ringBuffer (ringBuffer *rb, unsigned char *pp, int sz)
 リングバッファにデータを格納する. More...
 
unsigned char * get_ringBuffer (ringBuffer *rb, int sz)
 リングバッファからデータを得る.要 free() More...
 
int seek_ringBuffer (ringBuffer *rb, int sz)
 リングバッファのデータポインタを seek する. More...
 
unsigned char * ref_ringBuffer (ringBuffer *ring, int pos)
 spoint 地点から pos番目のデータへの参照.posは 0から数える.spoint は変化しない. More...
 
int put_mstream (mstream *sb, unsigned char *pp)
 メッセージ(文字列)ストリーム sb へメッセージ(の一部)を格納する More...
 
unsigned char * get_mstream (mstream *sb)
 メッセージ(文字列)ストリーム sb から次のメッセージを取り出す.改行コードは削除される. More...
 
unsigned char * fgets_mstream (unsigned char *mesg, mstream *sb)
 メッセージストリームからメッセージを一行だけ取り出す. More...
 
unsigned char * uuid2guid (unsigned char *p)
 uuid を guid に変換する.要 free() More...
 
unsigned char * guid2uuid (unsigned char *p)
 guid を uuid に変換する.要 free() More...
 
long unsigned int get_used_memory (void)
 使用中のメモリサイズを得る. More...
 
long unsigned int get_free_memory (void)
 未使用のメモリサイズを得る. More...
 
void memory_check_start (void)
 
long unsigned int memory_check (void)
 
void set_sigterm_child (void(*handler)(int))
 child プロセス終了時の処理を設定. More...
 
void sigterm_child (int signal)
 child プロセス終了時の処理 More...
 
void ignore_sigterm_child (void)
 以後 child プロセスの終了を無視する. More...
 
void set_sigsegv_handler (void(*handler)(int))
 セグメンテーションエラー時のハンドラを設定 More...
 
void trap_segmentation_falt (int signal)
 セグメンテーションエラー時にデフォルトで呼び出される関数. More...
 
void open_logfile (void)
 デフォルトのログファイルをオープンする More...
 
void close_logfile (void)
 デフォルトのログファイルをクローズする More...
 
void print_logfile (const char *,...)
 デフォルトのログファイルにデータを書き込む More...
 
void open_errfile (void)
 デフォルトのエラーファイルをオープンする More...
 
void close_errfile (void)
 デフォルトのエラーファイルをクローズする More...
 
void print_errfile (const char *,...)
 デフォルトのエラーファイルにデータを書き込む More...
 
void print_message (const char *,...)
 バッファリングなしのメッセージ出力(stderr) More...
 
void fprint_message (FILE *, const char *,...)
 バッファリングなしのメッセージ出力 More...
 

Variables

int DebugMode
 ON の場合 ライブラリ全体がデバックモードであることを示す.デフォルトは OFF. More...
 
int UnitTestMode
 ユニット単体でのテストを行う場合に使用する.デフォルトは OFF. More...
 
int KanjiCode
 処理用漢字コード.CODE_US, CODE_SJIS, CODE_EDUがある.デフォルトは CODE_US. More...
 
int HostEndian
 ホストの Endian More...
 
unsigned char LocalIPNum [4]
 127.0.0.1 のバイナリ More...
 
unsigned char LocalIPNum6 [16]
 ::1 のバイナリ More...
 
long unsigned int UsedMemoryBase
 メモリチェック用 More...
 
FILE * FP_LogFile
 
FILE * FP_ErrFile
 

Detailed Description

Author
Fumi.Iseki (C)
Date
2020 10/27

Definition in file tools.h.

Macro Definition Documentation

◆ _tochar

#define _tochar (   a)    (char*)(a)

Definition at line 207 of file tools.h.

◆ BIG_ENDIAN

#define BIG_ENDIAN   4321

Definition at line 92 of file tools.h.

◆ cat_file

#define cat_file (   src,
  dst 
)    file_from_to((src), (dst), "ab")

Definition at line 420 of file tools.h.

◆ CHAR_CR

#define CHAR_CR   0x0d

Definition at line 78 of file tools.h.

◆ CHAR_DELI_DIR

#define CHAR_DELI_DIR   '/'

Definition at line 102 of file tools.h.

◆ CHAR_LF

#define CHAR_LF   0x0a

Definition at line 79 of file tools.h.

◆ CHAR_TAB

#define CHAR_TAB   0x09

Definition at line 80 of file tools.h.

◆ clear_mstream

#define clear_mstream (   s)    clear_ringBuffer((s))

Definition at line 388 of file tools.h.

◆ CODE_EN

#define CODE_EN   0

Definition at line 83 of file tools.h.

◆ CODE_EUC

#define CODE_EUC   1

Definition at line 84 of file tools.h.

◆ CODE_SJIS

#define CODE_SJIS   2

Definition at line 85 of file tools.h.

◆ CODE_US

#define CODE_US   0

Definition at line 82 of file tools.h.

◆ CODE_UTF8

#define CODE_UTF8   3

Definition at line 86 of file tools.h.

◆ copy_file

#define copy_file (   src,
  dst 
)    file_from_to((src), (dst), "wb")

Definition at line 419 of file tools.h.

◆ DEBUG_ERROR

#define DEBUG_ERROR   PRINT_ERROR

Definition at line 513 of file tools.h.

◆ DEBUG_INFO

#define DEBUG_INFO   PRINT_INFO

Definition at line 511 of file tools.h.

◆ DEBUG_MESG

#define DEBUG_MESG   PRINT_MESG

Definition at line 514 of file tools.h.

◆ DEBUG_MODE

#define DEBUG_MODE   if(DebugMode==ON)

Definition at line 502 of file tools.h.

◆ DEBUG_WARN

#define DEBUG_WARN   PRINT_WARN

Definition at line 512 of file tools.h.

◆ del_mstream

#define del_mstream (   s)    del_ringBuffer((s))

Definition at line 387 of file tools.h.

◆ dup_string

#define dup_string (   s)    dup_str((s))

Definition at line 223 of file tools.h.

◆ EBUG

#define EBUG

Definition at line 490 of file tools.h.

◆ ex_strcmp

#define ex_strcmp (   a,
 
)    ex_strncasecmp((a), (b), -1)

Definition at line 283 of file tools.h.

◆ free_mstream

#define free_mstream (   s)    free_ringBuffer((s))

Definition at line 386 of file tools.h.

◆ free_null

#define free_null (   p)    freeNull((p))

Definition at line 205 of file tools.h.

◆ freeNull

#define freeNull (   p)    {if(!isNull((void*)p)) free(p); (p)=NULL;}

Definition at line 201 of file tools.h.

◆ freenull

#define freenull (   p)    {if(!isNull((void*)p)) free(p); (p)=NULL;}

Definition at line 202 of file tools.h.

◆ hton_ar

#define hton_ar (   p,
 
)    {if(!isBigEndian) swap_byte((void*)(p),(s),sizeof(*(p)));}

Definition at line 428 of file tools.h.

◆ hton_data

#define hton_data (   p,
  s,
 
)    {if(!isBigEndian) swap_byte((void*)(p),(s),(c));}

Definition at line 431 of file tools.h.

◆ hton_st

#define hton_st (   p,
 
)    {if(!isBigEndian) swap_byte((void*)(p),sizeof(*(p)),(s));}

Definition at line 426 of file tools.h.

◆ htonull

#define htonull (   s)    ntohull((s))

Definition at line 262 of file tools.h.

◆ init_mstream

#define init_mstream ( )    init_ringBuffer()

Definition at line 383 of file tools.h.

◆ int_swap

#define int_swap (   p,
 
)    {int swap=(p); (p)=(s); (s)=swap;}

Definition at line 270 of file tools.h.

◆ isBigEndian

#define isBigEndian   (is_big_endian())

Definition at line 422 of file tools.h.

◆ isLittleEndian

#define isLittleEndian   (is_little_endian())

Definition at line 423 of file tools.h.

◆ JBXL_ERR_FILE

#define JBXL_ERR_FILE   "/var/log/jbxl.err"

Definition at line 444 of file tools.h.

◆ JBXL_LOG_FILE

#define JBXL_LOG_FILE   "/var/log/jbxl.log"

Definition at line 443 of file tools.h.

◆ LITTLE_ENDIAN

#define LITTLE_ENDIAN   1234

Definition at line 91 of file tools.h.

◆ LOCAL_IPADDR

#define LOCAL_IPADDR   LOCAL_IPv4

Definition at line 193 of file tools.h.

◆ LOCAL_IPADDR6

#define LOCAL_IPADDR6   LOCAL_IPv6

Definition at line 194 of file tools.h.

◆ LOCAL_IPv4

#define LOCAL_IPv4   "127.0.0.1"

Definition at line 191 of file tools.h.

◆ LOCAL_IPv6

#define LOCAL_IPv6   "::1"

Definition at line 192 of file tools.h.

◆ make_mstream

#define make_mstream (   s)    make_ringBuffer((s))

Definition at line 385 of file tools.h.

◆ mstream

#define mstream   ringBuffer

Definition at line 167 of file tools.h.

◆ new_mstream

#define new_mstream (   s)    new_ringBuffer((s))

Definition at line 384 of file tools.h.

◆ NO_DEBUG_MODE

#define NO_DEBUG_MODE   if(DebugMode==OFF)

Definition at line 503 of file tools.h.

◆ ntoh_ar

#define ntoh_ar (   p,
 
)    {if(!isBigEndian) swap_byte((void*)(p),(s),sizeof(*(p)));}

Definition at line 427 of file tools.h.

◆ ntoh_data

#define ntoh_data (   p,
  s,
 
)    {if(!isBigEndian) swap_byte((void*)(p),(s),(c));}

Definition at line 430 of file tools.h.

◆ ntoh_st

#define ntoh_st (   p,
 
)    {if(!isBigEndian) swap_byte((void*)(p),sizeof(*(p)),(s));}

Definition at line 425 of file tools.h.

◆ pack_char

#define pack_char (   s,
 
)    pack_char_len((s), (c), -1)

Definition at line 236 of file tools.h.

◆ PDP_ENDIAN

#define PDP_ENDIAN   3412

Definition at line 93 of file tools.h.

◆ PRINT_ERROR

#define PRINT_ERROR   print_message

Definition at line 479 of file tools.h.

◆ PRINT_ESC

#define PRINT_ESC   print_escape

Definition at line 476 of file tools.h.

◆ print_hex

#define print_hex (   o,
  m,
 
)    fdump((o), (m), (n))

Definition at line 313 of file tools.h.

◆ PRINT_INFO

#define PRINT_INFO   print_message

Definition at line 477 of file tools.h.

◆ PRINT_MESG

#define PRINT_MESG   print_message

Definition at line 475 of file tools.h.

◆ PRINT_WARN

#define PRINT_WARN   print_message

Definition at line 478 of file tools.h.

◆ random_str

#define random_str (   n)    temp_filename(NULL, (n))

Definition at line 351 of file tools.h.

◆ set_sigseg_handler

#define set_sigseg_handler (   h)    set_sigsegv_handler((h))

Definition at line 411 of file tools.h.

◆ STR_CRNT_DIR

#define STR_CRNT_DIR   "./"

Definition at line 104 of file tools.h.

◆ STR_DELI_DIR

#define STR_DELI_DIR   "/"

Definition at line 103 of file tools.h.

◆ STR_UPST_DIR

#define STR_UPST_DIR   "../"

Definition at line 105 of file tools.h.

◆ UNKNOWN_ENDIAN

#define UNKNOWN_ENDIAN   0

Definition at line 88 of file tools.h.

Function Documentation

◆ awk()

char* awk ( char *  buf,
char  cc,
int  n 
)

char* awk(char* buf, char cc, int n)

ccを区切り記号として, strのバッファ内の n番目の項目を返す. 返されたデータは free()する必要がある.

Parameters
buf操作対象文字列.
cc区切り文字.
n項目の指定. 1から数える.
Returns
指定された n番目の項目の文字列.要 free
See also
cawk()

Definition at line 567 of file tools.c.

568 {
569  int i, j, pos, cnt;
570  char* item = NULL;
571 
572  if (buf==NULL) return NULL;
573 
574  for(i=0,j=0; j<n-1; j++) {
575  while (buf[i]!='\0' && buf[i]!=cc) i++;
576  if (buf[i]==cc) i++;
577  }
578  if (buf[i]=='\0') return NULL;
579 
580  pos = i;
581  while (buf[i]!='\0' && buf[i]!=cc) i++;
582  cnt = i - pos;
583 
584  item = (char*)malloc(cnt+1);
585  if (item==NULL) return NULL;
586 
587  for (i=0; i<cnt; i++) item[i] = buf[pos+i];
588  item[cnt] = '\0';
589 
590  return item;
591 }
unsigned char ** buf
Definition: jpeg_tool.h:96

References buf.

Referenced by awk_tList(), decode_mime_rfc2047(), decode_mime_rfc2231(), get_smtp_rcpt(), is_smtp_onecommand(), to_address_num(), to_address_num4(), to_address_num8(), and to_ipaddress_list().

Here is the caller graph for this function:

◆ bincmp()

int bincmp ( unsigned char *  b1,
unsigned char *  b2,
int  n 
)

int bincmp(unsigned char* b1, unsigned char* b2, int n)

バイナリデータ s1と s2 nバイト比較する.

Parameters
b1比較するバイナリデータ1
b2比較するバイナリデータ2
n比較するバイト数
Return values
0一致する
1一致しない
Attention
strncmp()の戻り値の定義とは若干異なるので注意すること.

Definition at line 650 of file tools.c.

651 {
652  int i;
653 
654  if (b1==NULL || b2==NULL) return 1;
655 
656  for (i=0; i<n; i++) {
657  if (b1[i]!=b2[i]) return 1;
658  }
659 
660  return 0;
661 }

◆ cawk()

char* cawk ( char *  buf,
char  cc,
int  n 
)

char* cawk(char* buf, char cc, int n)

ccを区切り記号として, strのバッファ内の n番目の項目を返す.

n は 1から数える.連続する cc(区切り)は一つの区切りとみなす. 返されたデータは free()する必要がある.

Parameters
buf操作対象文字列.
cc区切り文字.
n項目の指定.
Returns
指定された n番目の項目の文字列.要 free.
See also
awk()

Definition at line 609 of file tools.c.

610 {
611  int i, j, pos, cnt;
612  char* item = NULL;
613 
614  if (buf==NULL) return NULL;
615 
616  for(i=0,j=0; j<n-1; j++) {
617  while (buf[i]!='\0' && buf[i]!=cc) i++;
618  while (buf[i]!='\0' && buf[i]==cc) i++;
619  }
620  if (buf[i]=='\0') return NULL;
621 
622  pos = i;
623  while (buf[i]!='\0' && buf[i]!=cc) i++;
624  cnt = i - pos;
625 
626  item = (char*)malloc(cnt+1);
627  if (item==NULL) return NULL;
628 
629  for (i=0; i<cnt; i++) item[i] = buf[pos+i];
630  item[cnt] = '\0';
631 
632  return item;
633 }

References buf.

Referenced by cawk_tList().

Here is the caller graph for this function:

◆ change_esc()

char* change_esc ( char *  mesg)

char* change_esc(char* mesg)

文字列中の CR, LF を \r, \n に変換する. 返されたデータは free()する必要がある.

Parameters
mesg操作対象の文字列
Returns
変換後の文字列.要 free

Definition at line 1210 of file tools.c.

1211 {
1212  int i, j;
1213  char* pp;
1214 
1215  if (mesg==NULL) return NULL;
1216 
1217  pp = (char*)malloc((strlen(mesg)+1)*2);
1218  if (pp==NULL) return NULL;
1219  memset(pp, 0, (strlen(mesg)+1)*2);
1220 
1221  i = j = 0;
1222  while(mesg[i]!='\0') {
1223  if (mesg[i]==CHAR_CR) {
1224  pp[j++] = '\\';
1225  pp[j++] = 'r';
1226  }
1227  else if (mesg[i]==CHAR_LF) {
1228  pp[j++] = '\\';
1229  pp[j++] = 'n';
1230  }
1231  else {
1232  pp[j++] = mesg[i];
1233  }
1234  i++;
1235  }
1236  pp[j] = '\0';
1237 
1238  return pp;
1239 }
#define CHAR_CR
改行
Definition: tools.h:78
#define CHAR_LF
ラインフィード
Definition: tools.h:79

References CHAR_CR, and CHAR_LF.

Referenced by fprint_escape(), and print_escape().

Here is the caller graph for this function:

◆ check_endian()

void check_endian ( void  )

void check_endian(void)

大域変数 HostEndianLITTLE_ENDIANBIG_ENDIAN を設定する.

See also
HostEndian

Definition at line 143 of file tools.c.

144 {
146 }
int HostEndian
システムの Endian
Definition: tools.c:21
int is_little_endian(void)
エンディアンの動的チェック
Definition: tools.c:80
#define UNKNOWN_ENDIAN
Definition: tools.h:88

References HostEndian, is_little_endian(), and UNKNOWN_ENDIAN.

Referenced by double_from_big_endian(), double_from_little_endian(), float_from_big_endian(), float_from_little_endian(), int_from_big_endian(), int_from_little_endian(), short_from_big_endian(), short_from_little_endian(), uint_from_big_endian(), uint_from_little_endian(), ushort_from_big_endian(), and ushort_from_little_endian().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ chomp()

char* chomp ( char *  buf)

char* chomp(char* buf)

最初の改行コード以降を無視する.最初の改行コードのある場所に '\0' を代入する.

Parameters
[in,out]buf改行を無効にする文字列.
Returns
処理された buf[] へのポインタ.

Definition at line 921 of file tools.c.

922 {
923  int i, len;
924 
925  if (buf==NULL) return NULL;
926 
927  len = (int)strlen(buf);
928  for (i=0; i<len; i++) {
929  if (buf[i]==CHAR_LF || buf[i]==CHAR_CR) {
930  buf[i] = '\0';
931  return buf;
932  }
933  }
934  return buf;
935 }
unsigned char unsigned long * len
Definition: jpeg_tool.h:96

References buf, CHAR_CR, CHAR_LF, and len.

Referenced by get_mstream().

Here is the caller graph for this function:

◆ clear_ringBuffer()

void clear_ringBuffer ( ringBuffer rb)

void clear_ringBuffer(ringBuffer* rb)

リングバッファ rb のデータをクリア(初期化)する.

Parameters
rbリングバッファへのポインタ

Definition at line 3313 of file tools.c.

3314 {
3315  if (rb!=NULL) {
3316  int sz = rb->bufsz;
3317  unsigned char* ptr = rb->buf;
3318  memset(rb->buf, 0, rb->bufsz);
3319  memset(rb, 0, sizeof(ringBuffer));
3320  rb->buf = ptr;
3321  rb->state = JBXL_NORMAL;
3322  rb->bufsz = sz;
3323  }
3324 }
#define JBXL_NORMAL
正常
Definition: jbxl_state.h:32
int bufsz
バッファ部のサイズ
Definition: tools.h:157
int state
リングバッファの状態
Definition: tools.h:163
unsigned char * buf
バッファ
Definition: tools.h:156

References ringBuffer::buf, ringBuffer::bufsz, JBXL_NORMAL, and ringBuffer::state.

◆ close_errfile()

void close_errfile ( void  )

void close_errfile(void)

デフォルトのエラーファイルをクローズする

Definition at line 3991 of file tools.c.

3992 {
3993  if (FP_ErrFile==NULL) return;
3994 
3995  fclose(FP_ErrFile);
3996  FP_ErrFile = NULL;
3997 
3998  return;
3999 }
FILE * FP_ErrFile
Definition: tools.c:3894

References FP_ErrFile.

◆ close_logfile()

void close_logfile ( void  )

void close_logfile(void)

デフォルトのログファイルをクローズする

Definition at line 3916 of file tools.c.

3917 {
3918  if (FP_LogFile==NULL) return;
3919 
3920  fclose(FP_LogFile);
3921  FP_LogFile = NULL;
3922 
3923  return;
3924 }
FILE * FP_LogFile
Definition: tools.c:3893

References FP_LogFile.

◆ count_lines()

int count_lines ( const char *  buf)

int count_lines(const char* buf)

文字列データ bufの行数を数える. 行頭が '\0' であっても 1行と数える

Parameters
buf行数を数える文字列データ
Returns
行数.

Definition at line 1673 of file tools.c.

1674 {
1675  int i = 0;
1676  int line = 0;
1677 
1678  if (buf==NULL) return 0;
1679  line++;
1680 
1681  while(buf[i]!='\0') {
1682  if (buf[i]==CHAR_CR) {
1683  line++;
1684  if (buf[i+1]==CHAR_LF) i++;
1685  }
1686  else if (buf[i]==CHAR_LF) {
1687  line++;
1688  }
1689  i++;
1690  }
1691 
1692  return line;
1693 }
void line(WSGraph vp, int x1, int y1, int x2, int y2, int cc)
Definition: graph.c:462

References buf, CHAR_CR, CHAR_LF, and line().

Here is the call graph for this function:

◆ cut_file_extension()

char* cut_file_extension ( const char *  str)

char* cut_file_extension(const char* str)

拡張子を削除したパス名を生成する.strは変化しない.要 free.

Parameters
strファイルのフルパス
Returns
str中のファイル名へのポインタ

Definition at line 2282 of file tools.c.

2283 {
2284  if (str==NULL) return NULL;
2285 
2286  char cc = '.';
2287  int len = (int)strlen(str);
2288  char* path = (char*)malloc(len+1);
2289  memcpy(path, str, len+1);
2290 
2291  int sz = len - 1;
2292  while (sz>=0 && path[sz]!=cc) sz--;
2293 
2294  if (sz<1) return path;
2295  path[sz] = '\0';
2296 
2297  return path;
2298 }

References len.

◆ cut_str()

char* cut_str ( char *  buf,
int  ls,
int  le 
)

char* cut_str(char* buf, int ls, int le)

buf[ls] 〜 buf[le] を切り出してメモリに格納して返す. 返されたデータは free()する必要がある.

Parameters
buf操作対象の文字列
ls切り出し開始の位置
le切り出し終了の位置
Returns
切り出した文字列.要 free

Definition at line 1338 of file tools.c.

1339 {
1340  int i, len;
1341  char* ret;
1342 
1343  if (buf==NULL) return NULL;
1344 
1345  ls = Max(ls, 0);
1346  le = Min(le, (int)strlen((const char*)buf));
1347  len = le - ls + 1;
1348  if (len<=0) return NULL;
1349 
1350  ret = (char*)malloc(len+1);
1351  if (ret==NULL) return NULL;
1352  memset(ret, 0, len+1);
1353 
1354  for (i=0; i<len; i++) ret[i] = buf[i+ls];
1355 
1356  return ret;
1357 }
#define Min(x, y)
Definition: common.h:250
#define Max(x, y)
Definition: common.h:247

References buf, len, Max, and Min.

Referenced by check_passwd(), command_USERID(), and x2crypt().

Here is the caller graph for this function:

◆ decode_base64()

unsigned char* decode_base64 ( unsigned char *  buf,
int *  sz 
)

unsigned char* decode_base64(unsigned char* buf, int* sz)

bufを base64からデコードする.

変換は bufの先頭から順次行われる.A-Za-z0-9+/ 以外は無視する(例えば改行コード).
入力バッファ部が 4byte(6bit*4)の場合, 出力バッファ部は 3byte(8bit*3)となる. 入力バッファ部のバイト数が 4の倍数でない場合(不正なデータ), 足りない入力バッファ部には '='が挿入されているものとみなす.

返されたデータは free()する必要がある.

Parameters
bufbase64からデコードする文字列.
[in,out]szin: sz デコードされたデータの長さを格納する intへのポインタ.NULLでも良い.
out: デコードされたデータのサイズ.
Returns
base64からデコードされたデータ.要 free
"QQ" をデコードすると 'A',0x00 となる.

Definition at line 2787 of file tools.c.

2788 {
2789  int i, j, cc=0, bas, lt, ln;
2790  unsigned char* dcd;
2791 
2792  lt = 0;
2793  ln = (int)strlen((const char*)buf);
2794  while (buf[lt]!='=' && lt<ln) {
2795  lt++;
2796  if (lt==ln) break;
2797  }
2798 
2799  int len = lt/4*3 + (lt%4)*3/4;
2800  if (sz!=NULL) *sz = len;
2801 
2802  dcd = (unsigned char*)malloc(len+1);
2803  if (dcd==NULL) return NULL;
2804  memset(dcd, 0, len+1);
2805 
2806  for (i=0; i<lt; i++) {
2807  if (buf[i]>='A' && buf[i]<='Z') cc = buf[i] - 'A';
2808  else if (buf[i]>='a' && buf[i]<='z') cc = buf[i] - 'a' + 26;
2809  else if (buf[i]>='0' && buf[i]<='9') cc = buf[i] - '0' + 52;
2810  else if (buf[i]=='+') cc = 62;
2811  else if (buf[i]=='/') cc = 63;
2812 
2813  if (cc<64) {
2814  bas = 32;
2815  for (j=0; j<6; j++) {
2816  setBit(dcd, i*6+j, cc/bas);
2817  cc = cc%bas;
2818  bas = bas/2;
2819  }
2820  }
2821  }
2822  return dcd;
2823 }
#define setBit(x, n, i)
Definition: common.h:259

References buf, len, and setBit.

Referenced by decode_base64_Buffer(), decode_base64_filename(), and decode_mime_rfc2047().

Here is the caller graph for this function:

◆ decode_base64_filename()

unsigned char* decode_base64_filename ( unsigned char *  buf,
int *  sz,
unsigned char  cc 
)

unsigned char* decode_base64_filename(unsigned char* buf, int* sz, unsigned char cc)

bufを Base64で decodeしてバイナリデータを取り出す.ただし cc は '/' として扱う.

Definition at line 2888 of file tools.c.

2889 {
2890  if (cc==0x00) cc = '-';
2891 
2892  int i, len = (int)strlen((char*)buf);
2893  for (i=0; i<len; i++) {
2894  if (buf[i]==cc) buf[i] = '/';
2895  }
2896 
2897  unsigned char* dec = decode_base64(buf, sz);
2898 
2899  return dec;
2900 }
unsigned char * decode_base64(unsigned char *buf, int *sz)
bufを base64からデコードする.要 free()
Definition: tools.c:2787

References buf, decode_base64(), and len.

Here is the call graph for this function:

◆ decode_hex()

unsigned char decode_hex ( unsigned char  pp1,
unsigned char  pp2 
)

unsigned char decode_hex(unsigned char pp1, unsigned char pp2)

16進コードをキャラクタに変換する.O-9,A-F以外が指定された場合は0とみなす.

Parameters
pp116進コードの上位4Bit. 0-9,A-F
pp216進コードの下位4Bit. 0-9,A-F
Returns
指定されたASCIIコードのキャラクタ
例:decode_hex('2', '0') は ' ' を返す.

Definition at line 3172 of file tools.c.

3173 {
3174  unsigned char ret;
3175 
3176  if (pp1>=0x30 && pp1<=0x39) pp1 -= 0x30; // 0-9
3177  else if (pp1>=0x41 && pp1<=0x46) pp1 -= 0x37; // A-F
3178  else if (pp1>=0x61 && pp1<=0x66) pp1 -= 0x57; // a-f
3179  else pp1 = 0x00;
3180 
3181  if (pp2>=0x30 && pp2<=0x39) pp2 -= 0x30; // 0-9
3182  else if (pp2>=0x41 && pp2<=0x46) pp2 -= 0x37; // A-F
3183  else if (pp2>=0x41 && pp2<=0x46) pp2 -= 0x57; // a-f
3184  else pp1 = 0x00;
3185 
3186  ret = (pp1<<4) + pp2;
3187  return ret;
3188 }

Referenced by decode_quoted_printable(), and decode_urlenc().

Here is the caller graph for this function:

◆ decode_quoted_printable()

unsigned char* decode_quoted_printable ( unsigned char *  buf,
int *  sz 
)

unsigned char* decode_quoted_printable(unsigned char* buf, int* sz)

buf を quoted printableからデコードする. 返されたデータは free()する必要がある.

Parameters
bufデコードする文字列.
[out]szデコードされたデータの長さを格納する変数.
Returns
デコードされたデータ

Definition at line 3030 of file tools.c.

3031 {
3032  int i, j, len;
3033  unsigned char* dec;
3034 
3035  len = (int)strlen((const char*)buf) + 1;
3036  dec = (unsigned char*)malloc(len);
3037  if (dec==NULL) return NULL;
3038  memset(dec, 0, len);
3039 
3040  i = j = 0;
3041  while (buf[i]!='\0') {
3042  if (buf[i]=='=') {
3043  if (buf[i+1]=='\0') return dec;
3044  if (buf[i+2]=='\0') return dec;
3045  dec[j++] = decode_hex(buf[i+1], buf[i+2]);
3046  i += 2;
3047  }
3048  else {
3049  if (buf[i]=='_') dec[j++] = ' '; // RFC2047
3050  else dec[j++] = buf[i];
3051  }
3052  i++;
3053  }
3054 
3055  *sz = j;
3056  return dec;
3057 }
unsigned char decode_hex(unsigned char pp1, unsigned char pp2)
16進コードをキャラクタに変換する.O-9,A-F以外が指定された場合は0とみなす. 内容を書き換える.
Definition: tools.c:3172

References buf, decode_hex(), and len.

Referenced by decode_mime_rfc2047().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ decode_urlenc()

unsigned char* decode_urlenc ( unsigned char *  buf,
int *  sz 
)

unsigned char* decode_urlenc(unsigned char* buf, int* sz)

buf を URLエンコードからデコードする. 返されたデータは free()する必要がある.

Parameters
bufデコードする文字列.
[out]szデコードされたデータの長さを格納する変数.
Returns
デコードされたデータ.要 free

Definition at line 2933 of file tools.c.

2934 {
2935  int i, j, len;
2936  unsigned char* dec;
2937 
2938  if (buf==NULL) return NULL;
2939 
2940  len = (int)strlen((const char*)buf) + 1;
2941  dec = (unsigned char*)malloc(len);
2942  if (dec==NULL) return NULL;
2943  memset(dec, 0, len);
2944 
2945  i = j = 0;
2946  while (buf[i]!='\0') {
2947  if (buf[i]=='%') {
2948  if (buf[i+1]=='\0') return dec;
2949  if (buf[i+2]=='\0') return dec;
2950  dec[j++] = decode_hex(buf[i+1], buf[i+2]);
2951  i += 2;
2952  }
2953  else {
2954  if (buf[i]=='+') dec[j++] = ' ';
2955  else dec[j++] = buf[i];
2956  }
2957  i++;
2958  }
2959 
2960  *sz = j;
2961  return dec;
2962 }

References buf, decode_hex(), and len.

Referenced by decode_mime_rfc2231().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ del_file_extension()

char* del_file_extension ( const char *  str)

char* del_file_extension(const char* str)

フルパスから拡張子を削除する. strの中身を書き換えて,strを返す.free() してはいけない.

Parameters
strファイルのフルパス
Returns
str中のファイル名へのポインタ

Definition at line 2256 of file tools.c.

2257 {
2258  if (str==NULL) return NULL;
2259 
2260  char cc = '.';
2261  char* path = (char*)str;
2262 
2263  int len = (int)strlen(path);
2264  int sz = len - 1;
2265  while (sz>=0 && path[sz]!=cc) sz--;
2266 
2267  if (sz<1) return path;
2268  path[sz] = '\0';
2269 
2270  return path;
2271 }

References len.

◆ del_file_name()

char* del_file_name ( const char *  str)

char* del_file_name(const char* str)

フルパスからファイル名を削除する. strの中身を書き換えて,strを返す.free() してはいけない.

Parameters
strファイルのフルパス
Returns
str中のファイル名へのポインタ

Definition at line 2094 of file tools.c.

2095 {
2096  if (str==NULL) return NULL;
2097 
2098 #ifdef WIN32
2099  char cc = '\\';
2100 #else
2101  char cc = '/';
2102 #endif
2103 
2104  char* path = (char*)str;
2105  int len = (int)strlen(str);
2106  if (len==1) {
2107  if (path[0]==cc) return path;
2108  else return NULL;
2109  }
2110 
2111  int sz = len - 1;
2112  while (sz>=0 && str[sz]!=cc) sz--;
2113 
2114  if (sz<0) {
2115  path[0] = '.';
2116  path[1] = cc;
2117  path[2] = '\0';
2118  }
2119  else {
2120  path[sz+1] = '\0';
2121  }
2122 
2123  return path;
2124 }

References len.

◆ del_ringBuffer()

void del_ringBuffer ( ringBuffer **  rb)

void del_ringBuffer(ringBuffer** rb)

new_ringBuffer()で作り出したリングバッファを削除する.

Parameters
[in,out]rbin: 削除するリングバッファポインタへのポインタ.
out: *rb はNULLになる.
See also
ringBuffer, new_ringBuffer()

Definition at line 3233 of file tools.c.

3234 {
3235  if (rb!=NULL && *rb!=NULL) {
3236  freeNull((*rb)->buf);
3237  free(*rb);
3238  *rb = NULL;
3239  }
3240 }
#define freeNull(p)
Definition: tools.h:201

References freeNull.

◆ double_bs()

char* double_bs ( char *  str)

char* double_bs(char* str)

文字列中の バックスペース \を 2重 \\ に変えた文字列を返す. 返されたデータは free()する必要がある.

Parameters
str操作対象の文字列
Returns
変換された文字列.失敗した場合は NULL.要 free

Definition at line 2565 of file tools.c.

2566 {
2567  int i, j;
2568  int len, bsn=0;
2569  char* buf;
2570 
2571  len = (int)strlen(str);
2572  for (i=0; i<len; i++) if (str[i]=='\\') bsn++;
2573  buf = (char*)malloc(len+bsn+1);
2574  if (buf==NULL) return NULL;
2575  memset(buf, 0, len+bsn+1);
2576 
2577  for (i=0,j=0; i<len; i++) {
2578  buf[j++] = str[i];
2579  if (str[i]=='\\') buf[j++] = '\\';
2580  }
2581  buf[j] = '\0';
2582 
2583  return buf;
2584 }

References buf, and len.

◆ double_from_big_endian()

double double_from_big_endian ( void *  ptr)

double double_from_big_endian(void* ptr)

Big Endian形式で格納されている double型の値を取り出す.

Parameters
ptr変数が格納されているメモリへのポインタ
Returns
取り出した double型の値

Definition at line 264 of file tools.c.

265 {
266  double ret = *((double*)ptr);
267 
269  if (HostEndian==LITTLE_ENDIAN) reverse_str((uByte*)(&ret), 8);
270  return ret;
271 }
unsigned char uByte
1Byte
Definition: common.h:332
void reverse_str(uByte *p, int s)
バイト(octet)列を逆順にする.
Definition: tools.c:1952
void check_endian(void)
システムのエンディアンを判別して,大域変数 HostEndian に設定する
Definition: tools.c:143
#define LITTLE_ENDIAN
Definition: tools.h:91

References check_endian(), HostEndian, LITTLE_ENDIAN, reverse_str(), and UNKNOWN_ENDIAN.

Here is the call graph for this function:

◆ double_from_little_endian()

double double_from_little_endian ( void *  ptr)

double double_from_little_endian(void* ptr)

Little Endian形式で格納されている double型の値を取り出す.

Parameters
ptr変数が格納されているメモリへのポインタ
Returns
取り出した double型の値

Definition at line 156 of file tools.c.

157 {
158  double ret = *((double*)ptr);
159 
161  if (HostEndian==BIG_ENDIAN) reverse_str((uByte*)(&ret), 8);
162  return ret;
163 }
#define BIG_ENDIAN
Definition: tools.h:92

References BIG_ENDIAN, check_endian(), HostEndian, reverse_str(), and UNKNOWN_ENDIAN.

Referenced by draw_shape_polygon(), and read_shape_main_file().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ dtostr()

char* dtostr ( double  n)

char* dtostr(double n)

double型 nを文字列にして返す.

Parameters
n文字列に変換する値
Returns
変換された文字列.free() してはいけない.

Definition at line 1516 of file tools.c.

1517 {
1518  memset(_ToSTR, 0, LDATA);
1519  snprintf(_ToSTR, LDATA-1, "%f", n);
1520  return _ToSTR;
1521 }
#define LDATA
Definition: common.h:151
static char _ToSTR[LDATA]
作業用(文字変換)
Definition: tools.c:1410

References _ToSTR, and LDATA.

◆ dtostr_ts()

char* dtostr_ts ( double  n)

char* dtostr_ts(double n)

double型 nを文字列にして返す. Thread Safe

Parameters
n文字列に変換する値
Returns
変換された文字列.要 free.

Definition at line 1652 of file tools.c.

1653 {
1654  char* str = NULL;
1655  str = (char*)malloc(LDATA);
1656  if (str==NULL) return NULL;
1657 
1658  memset(str, 0, LDATA);
1659  snprintf(str, LDATA-1, "%f", n);
1660  return str;
1661 }

References LDATA.

Referenced by llsd_bin_main_parse(), and make_xml_attr_bydouble().

Here is the caller graph for this function:

◆ dup_str()

char* dup_str ( char *  buf)

char* dup_str(char* buf)

文字列 bufの複製を作り出す.返されたデータは free()する必要がある.

Parameters
bufコピー元の文字列
Returns
複製された文字列.要 free

Definition at line 1368 of file tools.c.

1369 {
1370  int len;
1371  char* ret;
1372 
1373  if (buf==NULL) return NULL;
1374 
1375  len = (int)strlen(buf);
1376  ret = (char*)malloc(len+1);
1377  if (ret==NULL) return NULL;
1378 
1379  memcpy(ret, buf, len);
1380  ret[len] = '\0';
1381 
1382  return ret;
1383 }

References buf, and len.

Referenced by get_string_from_json().

Here is the caller graph for this function:

◆ encode_base64()

unsigned char* encode_base64 ( unsigned char *  buf,
int  sz 
)

unsigned char* encode_base64(unsigned char* buf, int sz)

バイナリデータ bufを base64にエンコードする.

入力バッファ部が 3byte(8bit*3)の場合, 出力バッファ部は 4byte(6bit*4)となる. 入力バッファ部が 6bit境界でない場合, 6bit境界 まで 0が付加されたと見される.
出力バッファ部が 4byte境界でない場合, 4byte境界まで '='を付加して出力する. また,出力バッファ部での 60byte毎の改行は行わない.
一般に n byte 入力された場合, base64の出力の文字数は (n+2)/3*4 byte となる.

返されたデータは free()する必要がある.

Parameters
bufbase64にエンコードするデータ.
szデータの長さを示す.-1以下の場合は buf は文字列とみなす.
Returns
base64にエンコードされた文字列.要 free
'A',0x00,0x01 を文字列(sz=1)とみなして符号化すると "QQ==" となる.
'A',0x00,0x01 の 3byteを符号化(sz=3)すると "QQAB" となる.

Definition at line 2849 of file tools.c.

2850 {
2851  unsigned char base[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
2852  unsigned char bas;
2853  int i, j, len;
2854  unsigned char* ecd;
2855 
2856  if (buf==NULL) return NULL;
2857  if (sz<0) len = (int)strlen((const char*)buf);
2858  else len = sz;
2859  if (len<=0) return NULL;
2860 
2861  sz = ((len+2)/3)*4;
2862  ecd = (unsigned char*)malloc(sz+1);
2863  if (ecd==NULL) return NULL;
2864  memset(ecd, 0, sz+1);
2865 
2866  for (i=0; i<sz; i++) {
2867  bas = 0x00;
2868  if (len*8 > i*6) {
2869  for (j=0; j<6; j++) {
2870  if (len*8 > i*6+j) setBit(&bas, j+2, getBit(buf, i*6+j));
2871  //else setBit(&bas, j+2, 0);
2872  }
2873  ecd[i] = base[(int)bas];
2874  }
2875  else {
2876  ecd[i] = '=';
2877  }
2878  }
2879  return ecd;
2880 }
#define getBit(x, n)
Definition: common.h:258

References buf, getBit, len, and setBit.

Referenced by encode_base64_Buffer(), encode_base64_Buffer_bin(), encode_base64_filename(), encode_mime_string(), and temp_filename().

Here is the caller graph for this function:

◆ encode_base64_filename()

unsigned char* encode_base64_filename ( unsigned char *  buf,
int  sz,
unsigned char  cc 
)

unsigned char* encode_base64_filename(unsigned char* buf, int sz, unsiged char cc)

バイナリデータ bufを Base64で encodeしてファイル名を作る.ただし '/' は cc として扱う.

Definition at line 2908 of file tools.c.

2909 {
2910  if (cc==0x00) cc = '-';
2911 
2912  unsigned char* enc = encode_base64(buf, sz);
2913 
2914  int i, len = (int)strlen((char*)enc);
2915  for (i=0; i<len; i++) {
2916  if (enc[i]=='/') enc[i] = cc;
2917  }
2918 
2919  return enc;
2920 }
unsigned char * encode_base64(unsigned char *buf, int sz)
バイナリデータ bufを base64にエンコードする.要 free()
Definition: tools.c:2849

References buf, encode_base64(), and len.

Here is the call graph for this function:

◆ encode_hex()

unsigned char* encode_hex ( unsigned char  cc)

unsigned char* encode_hex(unsigned char cc)

キャラクタを16進コードの文字列に変換する. 返されたデータは free()する必要がある.

Parameters
cc変換するキャラクタ.
Returns
新しく確保された 3byteの領域
[0] 16進コードの上位4Bit. 0-9,A-F
[1] 16進コードの下位4Bit. 0-9,A-F
[2] '\0'
Return values
NULLメモリ不足.
encode_hex(' ') は "20" を返す.
unsigned char * encode_hex(unsigned char cc)
キャラクタを16進コードの文字列に変換する.要 free()
Definition: tools.c:3139

Definition at line 3139 of file tools.c.

3140 {
3141  unsigned char* ret;
3142  unsigned char pp1, pp2;
3143  unsigned char base[] = "0123456789ABCDEF";
3144 
3145  ret = (unsigned char*)malloc(3);
3146  if (ret==NULL) return NULL;
3147 
3148  pp1 = cc >> 4;
3149  pp2 = cc & 0x0f;
3150 
3151  ret[0] = base[pp1];
3152  ret[1] = base[pp2];
3153  ret[2] = '\0';
3154 
3155  return ret;
3156 }

Referenced by encode_quoted_printable(), and encode_urlenc().

Here is the caller graph for this function:

◆ encode_quoted_printable()

unsigned char* encode_quoted_printable ( unsigned char *  buf,
int  sz 
)

unsigned char* encode_quoted_printable(unsigned char* buf, int sz)

バイナリデータ bufを quoted printable にエンコードする.

RFC2047 に従い,' ' は '_' にエンコードする.
エンコードしない文字 '=', '_' 以外の 0x21-0x7e
エンコードする文字 '=', '_', 0x00-0x20, 0x7f-0xff

返されたデータは free()する必要がある.

Parameters
bufエンコードするデータ.
szエンコードするデータの長さ.-1以下の場合は buf は文字列とみなす.
Returns
エンコードされた文字列.要 free

Definition at line 3075 of file tools.c.

3076 {
3077  int i, j, len;
3078  unsigned char* enc;
3079 
3080  if (sz<0) sz = (int)strlen((const char*)buf);
3081  len = sz*3 + 1;
3082  enc = (unsigned char*)malloc(len);
3083  if (enc==NULL) return NULL;
3084  memset(enc, 0, len);
3085 
3086  for (i=0, j=0; i<sz; i++) {
3087  if (buf[i]=='=') { // 0x3d
3088  enc[j++] = '=';
3089  enc[j++] = '3';
3090  enc[j++] = 'D';
3091  }
3092  else if (buf[i]=='_') { // 0x5f
3093  enc[j++] = '=';
3094  enc[j++] = '5';
3095  enc[j++] = 'F';
3096  }
3097  else if (buf[i]==' ') { // 0x20 RFC2047
3098  enc[j++] = '_';
3099  }
3100  else if (buf[i]<=0x1f || buf[i]>=0x7f) {
3101  unsigned char* asc = encode_hex(buf[i]);
3102  if (asc==NULL) {
3103  free(enc);
3104  return NULL;
3105  }
3106  enc[j++] = '=';
3107  enc[j++] = asc[0];
3108  enc[j++] = asc[1];
3109  free(asc);
3110  }
3111  else {
3112  enc[j++] = buf[i];
3113  }
3114  }
3115 
3116  return enc;
3117 }

References buf, encode_hex(), and len.

Referenced by encode_mime_string().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ encode_urlenc()

unsigned char* encode_urlenc ( unsigned char *  buf,
int  sz 
)

unsigned char* encode_urlenc(unsigned char* buf, int sz)

バイナリデータ bufを URLエンコードする.

エンコードしない文字については色々な考え方があるが,最大公約数的に考えてこのプログラムでは以下のようにする.
エンコードしない文字 0-9, A-Z, a-z, -._

返されたデータは free()する必要がある.

Parameters
bufエンコードするデータ.
szエンコードするデータの長さ.-1以下の場合は buf は文字列とみなす.
Returns
エンコードされた文字列.要 free

Definition at line 2980 of file tools.c.

2981 {
2982  int i, j, len;
2983  unsigned char* enc;
2984 
2985  if (buf==NULL) return NULL;
2986 
2987  if (sz<0) sz = (int)strlen((const char*)buf);
2988  len = sz*3 + 1;
2989  enc = (unsigned char*)malloc(len);
2990  if (enc==NULL) return NULL;
2991  memset(enc, 0, len);
2992 
2993  for(i=0, j=0; i<sz; i++) {
2994  if (buf[i]==' ') { // 半角スペース
2995  enc[j++] = '+';
2996  }
2997  else if ((buf[i]>=0x30 && buf[i]<=0x39) || // 0-9
2998  (buf[i]>=0x41 && buf[i]<=0x5a) || // A-Z
2999  (buf[i]>=0x61 && buf[i]<=0x7a) || // a-z
3000  buf[i]=='-' || buf[i]=='.' || buf[i]=='_'){ // - . _
3001  enc[j++] = buf[i];
3002  }
3003  else {
3004  unsigned char* asc = encode_hex(buf[i]);
3005  if (asc==NULL) {
3006  free(enc);
3007  return NULL;
3008  }
3009  enc[j++] = '%';
3010  enc[j++] = asc[0];
3011  enc[j++] = asc[1];
3012  free(asc);
3013  }
3014  }
3015 
3016  return enc;
3017 }

References buf, encode_hex(), and len.

Referenced by add_form_urlenc(), encode_mime_string(), and make_form_urlenc().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ euc2sjis()

void euc2sjis ( unsigned char *  c1,
unsigned char *  c2 
)

void euc2sjis(unsigned char *c1, unsigned char *c2)

漢字コード変換.EUC → SJIS

Parameters
[in,out]c1変換する文字の第一バイト.内容が書き換えられる.
[in,out]c2変換する文字の第二バイト.内容が書き換えられる.

Definition at line 2688 of file tools.c.

2689 {
2690  if (*c1%2==0) *c2 -= 0x02;
2691  else{
2692  *c2 -= 0x61;
2693  if (*c2>0x7e) (*c2)++;
2694  }
2695 
2696  if (*c1<0xdf) {
2697  (*c1)++;
2698  *c1 /= 2;
2699  *c1 += 0x30;
2700  }
2701  else {
2702  (*c1)++;
2703  *c1 /= 2;
2704  *c1 += 0x70;
2705  }
2706 }

Referenced by kanji_convert_Buffer(), and kanji_convert_euc2sjis().

Here is the caller graph for this function:

◆ ex_strncasecmp()

int ex_strncasecmp ( const char *  dat,
const char *  key,
int  len 
)

int ex_strncasecmp(const char* dat, const char* key, int len)

拡張文字比較.ケース無視.

Parameters
dat比べる文字列1.
key比べる文字列2.
len1以上 一致させる長さ.
len0 完全一致.
len-1 dat の長さに合わせる.
len-2 key の長さに合わせる.
Return values
TRUE一致した
FALSE一致しなかった

Definition at line 820 of file tools.c.

821 {
822  if (dat==NULL || key==NULL) return FALSE;
823 
824  if (len==0) {
825  if (!strcasecmp(dat, key)) return TRUE;
826  }
827  else if (len>0) {
828  if (!strncasecmp(dat, key, len)) return TRUE;
829  }
830  else if (len<0) {
831  int sz;
832  if (len==-1) sz = (int)strlen(dat);
833  else sz = (int)strlen(key);
834  if (!strncasecmp(dat, key, sz)) return TRUE;
835  }
836 
837  return FALSE;
838 }
#define TRUE
Definition: common.h:226
#define FALSE
Definition: common.h:223

References FALSE, len, and TRUE.

Referenced by _next_strncasecmp_horizon_tTree(), _next_strncasecmp_vertical_tTree(), del_tList_key(), get_xml_attr_node(), strncasecmp_back_tList(), strncasecmp_tList(), and strncasecmp_tTree().

Here is the caller graph for this function:

◆ ex_strncaservscmp()

int ex_strncaservscmp ( const char *  dat,
const char *  key,
int  len 
)

int ex_strncaervscmp(const char* dat, const char* key, int len)

拡張文字比較.後ろから比べる.ケース無視.

Parameters
dat比べる文字列1.
key比べる文字列2.
len1以上 一致させる長さ.
len0 完全一致.
len-1 dat の長さに合わせる.
len-2 key の長さに合わせる.
Return values
TRUE一致した
FALSE一致しなかった

Definition at line 892 of file tools.c.

893 {
894  if (dat==NULL || key==NULL) return FALSE;
895 
896  if (len==0) {
897  if (!strcasecmp(dat, key)) return TRUE;
898  }
899  else if (len>0) {
900  if (!strncaservscmp(dat, key, len)) return TRUE;
901  }
902  else if (len<0) {
903  int sz;
904  if (len==-1) sz = (int)strlen(dat);
905  else sz = (int)strlen(key);
906  if (!strncaservscmp(dat, key, sz)) return TRUE;
907  }
908 
909  return FALSE;
910 }
int strncaservscmp(const char *s1, const char *s2, int n)
文字列 s1と s2を後ろから n文字比較する.大文字小文字は区別しない.一致するなら 0
Definition: tools.c:703

References FALSE, len, strncaservscmp(), and TRUE.

Referenced by strncaservscmp_back_tList(), and strncaservscmp_tList().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ex_strncmp()

int ex_strncmp ( const char *  dat,
const char *  key,
int  len 
)

int ex_strncmp(const char* dat, const char* key, int len)

拡張文字比較

Parameters
dat比べる文字列1.
key比べる文字列2.
len1以上 一致させる長さ.
len0 完全一致.
len-1 dat の長さに合わせる.
len-2 key の長さに合わせる.
Return values
TRUE一致した
FALSE一致しなかった

Definition at line 784 of file tools.c.

785 {
786  if (dat==NULL || key==NULL) return FALSE;
787 
788  if (len==0) {
789  if (!strcmp(dat, key)) return TRUE;
790  }
791  else if (len>0) {
792  if (!strncmp(dat, key, len)) return TRUE;
793  }
794  else if (len<0) {
795  int sz;
796  if (len==-1) sz = (int)strlen(dat);
797  else sz = (int)strlen(key);
798  if (!strncmp(dat, key, sz)) return TRUE;
799  }
800 
801  return FALSE;
802 }

References FALSE, len, and TRUE.

Referenced by _next_strncmp_horizon_tTree(), _next_strncmp_vertical_tTree(), replace_all_tTree_node(), strncmp_back_tList(), strncmp_tList(), and strncmp_tTree().

Here is the caller graph for this function:

◆ ex_strnrvscmp()

int ex_strnrvscmp ( const char *  dat,
const char *  key,
int  len 
)

int ex_strnrvscmp(const char* dat, const char* key, int len)

拡張文字比較.後ろから比べる.

Parameters
dat比べる文字列1.
key比べる文字列2.
len1以上 一致させる長さ.
len0 完全一致.
len-1 dat の長さに合わせる.
len-2 key の長さに合わせる.
Return values
TRUE一致した
FALSE一致しなかった

Definition at line 856 of file tools.c.

857 {
858  if (dat==NULL || key==NULL) return FALSE;
859 
860  if (len==0) {
861  if (!strcmp(dat, key)) return TRUE;
862  }
863  else if (len>0) {
864  if (!strnrvscmp(dat, key, len)) return TRUE;
865  }
866  else if (len<0) {
867  int sz;
868  if (len==-1) sz = (int)strlen(dat);
869  else sz = (int)strlen(key);
870  if (!strnrvscmp(dat, key, sz)) return TRUE;
871  }
872 
873  return FALSE;
874 }
int strnrvscmp(const char *s1, const char *s2, int n)
文字列 s1と s2を後ろから n文字比較する.一致するなら 0
Definition: tools.c:674

References FALSE, len, strnrvscmp(), and TRUE.

Referenced by strnrvscmp_back_tList(), and strnrvscmp_tList().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fdump()

void fdump ( FILE *  fp,
unsigned char *  mesg,
int  n 
)

void fdump(FILE* fp, unsigned char* mesg, int n)

デバッグ用 16進ダンプ出力.

mesgの nバイトを16進表示する.n<0 の場合は 文字列とみなす.

Parameters
fp出力するファイルへのポインタ.NULLの場合は stderr
mesg表示するデータ.
n表示するバイト数

Definition at line 4177 of file tools.c.

4178 {
4179  int i, j, mod, len;
4180  char ascii[16];
4181 
4182  if (fp==NULL) fp = stderr;
4183 
4184  if (mesg==NULL) {
4185  fprintf(fp, "(Dump Data is NULL)\n");
4186  return;
4187  }
4188 
4189  if (n<0) len = (int)strlen((const char*)mesg);
4190  else len = n;
4191 
4192  memset(ascii, 0x2e, 16);
4193  for (i=0, j=0; i<len; i++) {
4194  fprintf(fp, "%02x ", mesg[i]);
4195  if (mesg[i]>=0x20 && mesg[i]<=0x7e) ascii[j] = mesg[i];
4196  j++;
4197  if (j==16) {
4198  fprintf(fp, " ");
4199  for (j=0; j<16; j++) {
4200  fprintf(fp, "%c ", ascii[j]);
4201  }
4202  fprintf(fp, "\n");
4203  memset(ascii, 0x2e, 16);
4204  j = 0;
4205  }
4206  }
4207 
4208  mod = len%16;
4209  if (mod>0) {
4210  for (i=0; i<17-mod; i++) fprintf(fp, " ");
4211  for (i=0; i<mod; i++) fprintf(fp, "%c ", ascii[i]);
4212  }
4213  fprintf(fp, "\n");
4214 }

References len.

Referenced by dump_http_header(), and dump_tList().

Here is the caller graph for this function:

◆ fgets_mstream()

unsigned char* fgets_mstream ( unsigned char *  mesg,
mstream sb 
)

unsigned char* fgets_mstream(unsigned char* mesg, mstream* sb)

メッセージストリームからメッセージを一行だけ取り出す.

メッセージ mesg はメッセージストリームに一旦バッファリングされ,この関数により一行ずつ読み出される.
結果が返される時,行中の改行コードは削除され,行末には必ず \0 が入る.
メッセージストリームのバッファ部が確保されていない場合は,最初に呼び出された時点で確保される.
一旦この関数を使用して,受信データをバッファリングしたら,最後まで読み取りには必ず同じストリームを使用して
この関数を呼び出さばければならない.そうで無い場合は受信データの整合性は保証されない.

Parameters
mesgバッファに一旦格納されるメッセージ.NULLでも可.
[in]sbストリームバッファ(リングバッファ型のストリームバッファ).
[out]sbsb->buf バッファ部が確保さえていなければ,自動的に確保される.
[out]sbsb->state JBXL_ERROR: メッセージストリーム操作中は異常な状態にある.
[out]sbsb->state JBXL_NODATA: メッセージストリーム中に有効なデータがない.return は NULL
Returns
取り出した文字列へのポインタ

Definition at line 3592 of file tools.c.

3593 {
3594  int state = JBXL_NORMAL;
3595  unsigned char* pp;
3596 
3597  if (sb==NULL) return NULL;
3598  if (sb->buf==NULL) {
3599  *sb = make_mstream(RECVBUFSZ);
3600  if (sb->buf==NULL) return NULL;
3601  }
3602 
3603  if (mesg!=NULL) put_mstream(sb, mesg);
3604  if (sb->state<0) state = sb->state;
3605 
3606  if (sb->datano==0) {
3607  sb->state = JBXL_NODATA;
3608  return NULL;
3609  }
3610  pp = get_mstream(sb);
3611 
3612  if (sb->state>=0 && state<0) sb->state = state;
3613  return pp;
3614 }
#define RECVBUFSZ
256K
Definition: common.h:134
#define JBXL_NODATA
有効なデータが無い
Definition: jbxl_state.h:35
int put_mstream(mstream *sb, unsigned char *mesg)
メッセージ(文字列)ストリーム sb へメッセージ(の一部)を格納する
Definition: tools.c:3491
unsigned char * get_mstream(mstream *sb)
メッセージ(文字列)ストリーム sb から次のメッセージを取り出す.改行コードは削除される.
Definition: tools.c:3532
#define make_mstream(s)
make_ringBuffer()
Definition: tools.h:385

References get_mstream(), JBXL_NODATA, JBXL_NORMAL, make_mstream, put_mstream(), and RECVBUFSZ.

Referenced by fgets_mstream_Buffer().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ file_chmod_open()

FILE* file_chmod_open ( const char *  fn,
const char *  fm,
mode_t  mode 
)

FILE* file_chmod_open(const char* fn, const char* fm, mode_t mode)

指定したファイルが存在して読み込み可能であれば,属性をmode へ変更した後,ファイルを fmモードでオープンしなおして,ファイルポインタを返す.
存在しなければ,ファイルを作成して属性を変更し,その後,ファイルを fmモードでオープンしなおして, ファイルポインタを返す.
属性の指定方法については man 2 chmod を参照すること.

Parameters
fnファイル名
fmファイルモード,"r","w","a".....
mode属性.see... man 2 chmod
Return values
NULL以外オープンしたファイルポインタ
NULL失敗.

Definition at line 2366 of file tools.c.

2367 {
2368  FILE* fp;
2369 
2370  if (!file_exist(fn)) {
2371  if ((fp=fopen(fn,"wb"))==NULL) return NULL;
2372  fclose(fp);
2373  }
2374 
2375 #ifndef WIN32
2376  fp = NULL;
2377  if (chmod(fn, mode)) return fp;
2378 #endif
2379 
2380  fp = fopen(fn, fm);
2381  return fp;
2382 }
int file_exist(const char *fn)
ファイルの存在を検査する.
Definition: tools.c:2337

References file_exist().

Referenced by check_server_spki().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ file_exist()

int file_exist ( const char *  fn)

int file_exist(const char* fn)

指定したファイルが存在して読み込み可能であれば「真」をそうでなければ「偽」を返す.

ファイルを一度オープンして確認するので,時間が掛かる. 読み込み可能なファイルを確認するのであれば,file_size()の方が(たぶん)早い.

Parameters
fnファイル名
Return values
TRUEファイルが存在し,読みこみ可能.
FALSEファイルが存在しないか,または読みこみ不可能.

Definition at line 2337 of file tools.c.

2338 {
2339  FILE* fp;
2340 
2341  if (fn==NULL) return FALSE;
2342 
2343  if ((fp=fopen(fn,"rb"))==NULL) {
2344  return FALSE;
2345  }
2346  fclose(fp);
2347  return TRUE;
2348 }

References FALSE, and TRUE.

Referenced by file_chmod_open(), sql_open(), and temp_filename().

Here is the caller graph for this function:

◆ file_from_to()

int file_from_to ( const char *  src,
const char *  dst,
const char *  mode 
)

int file_from_to(const char* src, const char* dst, const char* mode)

modeに従って,ファイル srcを dstにコピーする.

Parameters
srcコピー元(ソース)ファイル名
dstコピー先(ディスティネーション)ファイル名
modeコピー先ファイルのオープンモード.fopenに同じ."r", "w", "a", "r+", "w+", "a+", ....
Return values
0以上コピーしたサイズ
JBXL_MALLOC_ERROR作業用メモリが足りない.
JBXL_FILE_EXIST_ERRORソースファイルが存在しない.(シンボリックリンクも×)
JBXL_FILE_OPEN_ERRORソースファイルのオープン失敗
JBXL_FILE_DESTOPEN_ERRORディスティネーションファイルのオープン失敗

Definition at line 1985 of file tools.c.

1986 {
1987  long int sz;
1988  unsigned char* buf;
1989  FILE* fp;
1990  size_t rs;
1991  UNUSED(rs);
1992 
1993  sz = file_size(src);
1994  if (sz<0) return JBXL_FILE_EXIST_ERROR;
1995  buf = (unsigned char*)malloc(sz);
1996  if (buf==NULL) return JBXL_MALLOC_ERROR;
1997  memset(buf, 0, sz);
1998 
1999  fp = fopen(src, "rb");
2000  if (fp==NULL) {
2001  free(buf);
2002  return JBXL_FILE_OPEN_ERROR;
2003  }
2004  rs = fread(buf, sz, 1, fp);
2005  fclose(fp);
2006 
2007  fp = fopen(dst, mode);
2008  if (fp==NULL) {
2009  free(buf);
2010  return JBXL_FILE_DESTOPEN_ERROR;
2011  }
2012  fwrite(buf, sz, 1, fp);
2013  fclose(fp);
2014 
2015  free(buf);
2016  return sz;
2017 }
#define UNUSED(x)
Definition: common.h:264
#define JBXL_FILE_EXIST_ERROR
ファイルが存在しない(シンボリックリンクもダメ).または既に存在する.
Definition: jbxl_state.h:48
#define JBXL_FILE_DESTOPEN_ERROR
ディスティネーションファイルのオープン失敗
Definition: jbxl_state.h:50
#define JBXL_MALLOC_ERROR
メモリ確保エラー
Definition: jbxl_state.h:41
#define JBXL_FILE_OPEN_ERROR
ファイルオープン エラー
Definition: jbxl_state.h:44
unsigned long int file_size(const char *fn)
ファイルの大きさを返す.
Definition: tools.c:2309

References buf, file_size(), JBXL_FILE_DESTOPEN_ERROR, JBXL_FILE_EXIST_ERROR, JBXL_FILE_OPEN_ERROR, JBXL_MALLOC_ERROR, and UNUSED.

Here is the call graph for this function:

◆ file_size()

long unsigned file_size ( const char *  fn)

unsigned long int file_size(const char* fn)

通常のファイルの大きさを返す.シンボリックリンクなどは 0.

Parameters
fnファイル名
Returns
ファイルのサイズ.ファイルが異常の場合は -2. fn が NULL の場合は -1

Definition at line 2309 of file tools.c.

2310 {
2311  if (fn==NULL) return -1;
2312 
2313  struct stat stbuf;
2314  stat(fn, &stbuf);
2315 
2316 #ifdef WIN32
2317  return stbuf.st_size;
2318 #else
2319  if (S_ISREG(stbuf.st_mode)) return stbuf.st_size;
2320  else return -2;
2321 #endif
2322 }

Referenced by file_from_to(), read_Buffer_file(), read_cmn_file(), read_cmn_header(), read_dicom_file(), read_file(), read_xxx_file(), send_http_file(), and send_http_res_file().

Here is the caller graph for this function:

◆ float_from_big_endian()

float float_from_big_endian ( void *  ptr)

float float_from_big_endian(void* ptr)

Big Endian形式で格納されている float型の値を取り出す.

Parameters
ptr変数が格納されているメモリへのポインタ
Returns
取り出した float型の値

Definition at line 282 of file tools.c.

283 {
284  float ret = *((float*)ptr);
285 
287  if (HostEndian==LITTLE_ENDIAN) reverse_str((uByte*)(&ret), 4);
288  return ret;
289 }

References check_endian(), HostEndian, LITTLE_ENDIAN, reverse_str(), and UNKNOWN_ENDIAN.

Here is the call graph for this function:

◆ float_from_little_endian()

float float_from_little_endian ( void *  ptr)

float float_from_little_endian(void* ptr)

Little Endian形式で格納されている float型の値を取り出す.

Parameters
ptr変数が格納されているメモリへのポインタ
Returns
取り出した float型の値

Definition at line 174 of file tools.c.

175 {
176  float ret = *((float*)ptr);
177 
179  if (HostEndian==BIG_ENDIAN) reverse_str((uByte*)(&ret), 4);
180  return ret;
181 }

References BIG_ENDIAN, check_endian(), HostEndian, reverse_str(), and UNKNOWN_ENDIAN.

Here is the call graph for this function:

◆ fp_from_to()

int fp_from_to ( FILE *  src,
FILE *  dst,
long int  sz 
)

int fp_from_to(FILE* src, FILE* dst, long int sz)

ファイル srcを dstにコピーする.

Parameters
srcコピー元(ソース)のファイルポインタ
dstコピー先(ディスティネーション)のファイルポインタ
szコピー元(ソース)のサイズ
Return values
0以上コピーしたサイズ
JBXL_MALLOC_ERROR作業用メモリが足りない.
JBXL_ARGS_ERRORファイルサイズの指定がおかしい.
JBXL_FILE_OPEN_ERRORソースファイルのオープン失敗.
JBXL_FILE_DESTOPEN_ERRORディスティネーションファイルのオープン失敗.

Definition at line 2035 of file tools.c.

2036 {
2037  unsigned char* buf;
2038  size_t rs;
2039  UNUSED(rs);
2040 
2041  if (sz<=0) return JBXL_ARGS_ERROR;
2042  if (src==NULL) return JBXL_FILE_OPEN_ERROR;
2043  if (dst==NULL) return JBXL_FILE_DESTOPEN_ERROR;
2044 
2045  buf = (unsigned char*)malloc(sz);
2046  if (buf==NULL) return JBXL_MALLOC_ERROR;
2047  memset(buf, 0, sz);
2048 
2049  rs = fread(buf, sz, 1, src);
2050  sz = (int)fwrite(buf, sz, 1, dst);
2051 
2052  free(buf);
2053  return sz;
2054 }
#define JBXL_ARGS_ERROR
不正な引数(NULLなど)
Definition: jbxl_state.h:42

References buf, JBXL_ARGS_ERROR, JBXL_FILE_DESTOPEN_ERROR, JBXL_FILE_OPEN_ERROR, JBXL_MALLOC_ERROR, and UNUSED.

◆ fprint_message()

void fprint_message ( FILE *  fp,
const char *  fmt,
  ... 
)

void fprint_message(FILE fp, const char fmt, ...)

バッファリング無しのメッセージ出力

Parameters
fp出力先のファイルポインタ
fmt出力フォーマット.printf() に準拠.
See also
printf()

Definition at line 4089 of file tools.c.

4090 {
4091  char* nfmt;
4092  int len;
4093 
4094  va_list args;
4095  va_start(args, fmt);
4096 
4097  len = (int)strlen(fmt);
4098  nfmt = (char*)malloc(len + 1);
4099  if (nfmt==NULL) return;
4100 
4101  strncpy(nfmt, fmt, len);
4102  nfmt[len] = '\0';
4103 
4104  vfprintf(fp, nfmt, args);
4105  fflush(fp);
4106  free(nfmt);
4107 
4108  va_end(args);
4109 
4110  return;
4111 }

References len.

Referenced by fprint_escape().

Here is the caller graph for this function:

◆ free_ringBuffer()

void free_ringBuffer ( ringBuffer rb)

void free_ringBuffer(ringBuffer* rb)

リングバッファのバッファ部を開放する.

Parameters
rbリングバッファへのポインタ

Definition at line 3296 of file tools.c.

3297 {
3298  if (rb!=NULL) {
3299  freeNull(rb->buf);
3300  memset(rb, 0, sizeof(ringBuffer));
3301  rb->state = JBXL_NORMAL;
3302  }
3303 }

References ringBuffer::buf, freeNull, JBXL_NORMAL, and ringBuffer::state.

◆ ftostr()

char* ftostr ( float  n)

char* ftostr(float n)

float型 nを文字列にして返す.

Parameters
n文字列に変換する値
Returns
変換された文字列.free() してはいけない.

Definition at line 1500 of file tools.c.

1501 {
1502  memset(_ToSTR, 0, LDATA);
1503  snprintf(_ToSTR, LDATA-1, "%f", n);
1504  return _ToSTR;
1505 }

References _ToSTR, and LDATA.

◆ ftostr_ts()

char* ftostr_ts ( float  n)

char* ftostr_ts(float n)

float型 nを文字列にして返す. Thread Safe

Parameters
n文字列に変換する値
Returns
変換された文字列.要 free.

Definition at line 1632 of file tools.c.

1633 {
1634  char* str = NULL;
1635  str = (char*)malloc(LDATA);
1636  if (str==NULL) return NULL;
1637 
1638  memset(str, 0, LDATA);
1639  snprintf(str, LDATA-1, "%f", n);
1640  return str;
1641 }

References LDATA.

Referenced by make_xml_attr_byfloat().

Here is the caller graph for this function:

◆ get_file_extension()

char* get_file_extension ( const char *  str)

char* get_file_extension(const char* str)

フルパスからファイル名の拡張子へのポインタを取り出す.

Parameters
strファイルのフルパス
Returns
str中のファイル名の拡張子(.を含まない)へのポインタ

Definition at line 2225 of file tools.c.

2226 {
2227  int sz, len;
2228  char* ext;
2229 
2230  if (str==NULL) return NULL;
2231 
2232  char pd = '.';
2233  char cc1 = '\\';
2234  char cc2 = '/';
2235 
2236  len = (int)strlen(str);
2237  sz = 0;
2238  while (sz<len && str[len-1-sz]!=cc1 && str[len-1-sz]!=cc2 && str[len-1-sz]!=pd) sz++;
2239 
2240  if (str[len-1-sz]!=pd) return NULL;
2241  ext = (char*)str + len - sz;
2242 
2243  return ext;
2244 }

References len.

Referenced by add_resource_list().

Here is the caller graph for this function:

◆ get_file_name()

char* get_file_name ( const char *  str)

char* get_file_name(const char* str)

フルパスからファイル名へのポインタを取り出す. str中のポインタを返すので,free() してはいけない.

Parameters
strファイルのフルパス
Returns
str中のファイル名へのポインタ

Definition at line 2066 of file tools.c.

2067 {
2068  if (str==NULL) return NULL;
2069 
2070 #ifdef WIN32
2071  char cc = '\\';
2072 #else
2073  char cc = '/';
2074 #endif
2075 
2076  int len = (int)strlen(str);
2077  int sz = 0;
2078  while (sz<len && str[len-1-sz]!=cc) sz++;
2079  char* fnm = (char*)str + len - sz;
2080 
2081  return fnm;
2082 }

References len.

Referenced by add_resource_list().

Here is the caller graph for this function:

◆ get_file_path()

char* get_file_path ( const char *  str)

char* make_file_path(const char* str)

フルパスからパスを生成する.strは変化しない.要 free.

非推奨:get_file_path() を使え.

Parameters
strファイルのフルパス
Returns
ファイルのフルパス(ファイル名を含まない). char* get_file_path(const char* str)

ファイルパスからパス部分のみを得る.strは変化しない.要 free.

Parameters
strファイルのパス
Returns
ファイルのパス(ファイル名を含まない).最後の '/' まはた '\' 付き

Definition at line 2191 of file tools.c.

2192 {
2193  if (str==NULL || str[0]=='\0') return NULL;
2194 
2195  int len = (int)strlen(str);
2196  char* path = (char*)malloc(len + 1);
2197  memcpy(path, str, len + 1);
2198 
2199  char cc1 = '\\';
2200  char cc2 = '/';
2201 
2202  int sz = len - 1;
2203  while (sz>=0 && path[sz]!=cc1 && path[sz]!=cc2) sz--;
2204 
2205  if (sz<0) {
2206  free(path);
2207  path = NULL;
2208  }
2209  else {
2210  path[sz+1] = '\0';
2211  }
2212 
2213  return path;
2214 }

References len.

◆ get_free_memory()

long unsigned int get_free_memory ( void  )

unsigned long int get_free_memory(void)

未使用のメモリサイズを得る.

Definition at line 3719 of file tools.c.

3720 {
3721  struct sysinfo info;
3722  sysinfo(&info);
3723 
3724  unsigned long int mem = info.freeram;
3725  return mem*info.mem_unit/1024;
3726 }

◆ get_gmt_timestamp()

char* get_gmt_timestamp ( time_t  date,
const char *  format 
)

Definition at line 454 of file tools.c.

455 {
456  char* buf = (char*)malloc(64);
457  memset(buf, 0, 64);
458 
459  struct tm tm = *gmtime(&date);
460  //struct tm tm = *localtime(&date);
461  strftime(buf, 63, format, &tm);
462 
463  return buf;
464 }

References buf.

Referenced by get_http_header_date().

Here is the caller graph for this function:

◆ get_graphic_extension()

char* get_graphic_extension ( uWord  tex)

Definition at line 4251 of file tools.c.

4252 {
4253  memset(_GraphicFileExtension, 0, L_OCT);
4254 
4255  uWord file = tex & 0x00f0;
4256  if (file==JBXL_TEXTURE_JPEG) memcpy(_GraphicFileExtension, ".jpeg", 5);
4257  else if (file==JBXL_TEXTURE_TIFF) memcpy(_GraphicFileExtension, ".tiff", 5);
4258  else if (file==JBXL_TEXTURE_PNG) memcpy(_GraphicFileExtension, ".png", 4);
4259  else if (file==JBXL_TEXTURE_TGA) memcpy(_GraphicFileExtension, ".tga", 4);
4260  else if (file==JBXL_TEXTURE_JP2K) memcpy(_GraphicFileExtension, ".jp2", 4);
4261  else if (file==JBXL_TEXTURE_RAS) memcpy(_GraphicFileExtension, ".ras", 4);
4262 
4263  return _GraphicFileExtension;
4264 }
unsigned short uWord
2Byte
Definition: common.h:334
#define JBXL_TEXTURE_PNG
0x0040
Definition: common.h:324
#define JBXL_TEXTURE_TGA
0x0050
Definition: common.h:325
#define JBXL_TEXTURE_TIFF
0x0030
Definition: common.h:323
#define JBXL_TEXTURE_RAS
0x0070 SUN RASTER 8bit
Definition: common.h:327
#define L_OCT
Definition: common.h:168
#define JBXL_TEXTURE_JP2K
0x0060
Definition: common.h:326
#define JBXL_TEXTURE_JPEG
0x0020
Definition: common.h:321
static char _GraphicFileExtension[L_OCT]
Definition: tools.c:4249

References _GraphicFileExtension, JBXL_TEXTURE_JP2K, JBXL_TEXTURE_JPEG, JBXL_TEXTURE_PNG, JBXL_TEXTURE_RAS, JBXL_TEXTURE_TGA, JBXL_TEXTURE_TIFF, and L_OCT.

◆ get_line()

char* get_line ( char *  buf,
int  n 
)

char* get_line(char* buf, int n)

文字型データstrのバッファ内の n行目を取り出す.改行コードは削除される.

取り出した行を char型変数のバッファに格納して返す.
バッファの最後が '\0' で終わっている場合,バッファを越えて行を読もうとした場合は NULL を返す.
'\0' で終わっていない場合,バッファが何処で終わりかを知る事は(簡単な方法では)できない.

返されたデータは free()する必要がある.

Parameters
buf操作対象文の字列型データ(含む改行)
n行の指定.1 から数える.
Returns
指定された n行目の文字列.改行は含まない.要 free

Definition at line 484 of file tools.c.

485 {
486  int i, j, pos, cnt;
487  char* ret = NULL;
488 
489  if (buf==NULL) return NULL;
490 
491  for(i=0,j=0; j<n-1; j++) {
492  while (buf[i]!=CHAR_LF && buf[i]!=CHAR_CR && buf[i]!='\0') i++;
493  while (buf[i]==CHAR_LF || buf[i]==CHAR_CR) i++;
494  }
495  if (buf[i]=='\0') return NULL;
496 
497  pos = i;
498  while (buf[i]!=CHAR_LF && buf[i]!=CHAR_CR && buf[i]!='\0') i++;
499  cnt = i - pos;
500 
501  if (cnt>=0) {
502  ret = (char*)malloc(cnt+1);
503  if (ret==NULL) return NULL;
504 
505  for(i=0; i<cnt; i++) ret[i] = buf[pos+i];
506  ret[cnt] = '\0';
507  }
508  return ret;
509 }

References buf, CHAR_CR, and CHAR_LF.

Referenced by command_PASSWD(), and x2crypt().

Here is the caller graph for this function:

◆ get_local_timestamp()

char* get_local_timestamp ( time_t  date,
const char *  format 
)

char* get_localtime(char c1, char c2, char c3, char c4)

非推奨.use get_local_timestamp(time(0), "%Y/%m/%dT%H:%M:%SZ")

ローカルタイムを "年c1月c1日c2時c3分c3秒c4" の形式で返す.
返ってきた char* ポインタは free() してはいけない.

Returns
"年c1月c1日c2時c3分c3秒c4" 形式のローカルタイム
printf("%s\n", get_localtime('/', 'T', ':', 'Z'));
2021/08/16T15:04:56Z

char* get_localtime_ts(char c1, char c2, char c3, char c4)

非推奨.use get_local_timestamp(time(0), "%Y/%m/%dT%H:%M:%SZ")

ローカルタイムを "年c1月c1日c2時c3分c3秒c4" の形式で返す.
返ってきた char* ポインタは free() すること.

Returns
"年c1月c1日c2時c3分c4秒c5" 形式のローカルタイム.要 free

Definition at line 440 of file tools.c.

441 {
442  char* buf = (char*)malloc(64);
443  memset(buf, 0, 64);
444 
445  //struct tm tm = *gmtime(&date);
446  struct tm tm = *localtime(&date);
447  strftime(buf, 63, format, &tm);
448 
449  return buf;
450 }

References buf.

◆ get_mstream()

unsigned char* get_mstream ( mstream sb)

unsigned char* get_mstream(mstream* sb)

メッセージ(文字列)ストリーム sb から次のメッセージを取り出す.改行コードは削除される.
ここで,メッセージとは \r\n, \r または \n で区切られている文字列でのことである.

Parameters
[in]sbメッセージストリームへのポインタ
[out]sbstate JBXL_NORMAL: ストリームは正常状態.JBXL_ERROR: ストリームは異常な状態にある.(未実装)
Return values
NULL以外取り出したストリームデータへのポインタ.要 free
NULLデータ取得失敗.現在有効なメッセージデータは無い.または単に失敗した.

Definition at line 3532 of file tools.c.

3533 {
3534  int n, len;
3535  unsigned char* pp;
3536 
3537  if (sb==NULL) return NULL;
3538  sb->state = JBXL_NORMAL;
3539  if (sb->buf==NULL) return NULL;
3540  if (sb->datano==0) return NULL;
3541 
3542  len = sb->npoint - sb->spoint;
3543  if (len==0) return NULL;
3544  else if (len<0) len += sb->bufsz;
3545 
3546  pp = get_ringBuffer(sb, len);
3547  if (pp==NULL) {
3548  sb->state = JBXL_ERROR;
3549  return NULL;
3550  }
3551  chomp((char*)pp);
3552 
3553  sb->datano += -1;
3554  sb->spoint = sb->npoint;
3555 
3556  if (sb->datano>=1) {
3557  int m;
3558  n = sb->spoint;
3559  while (n!=sb->epoint) {
3560  m = (n + 1) % sb->bufsz;
3561  if (sb->buf[n]==CHAR_LF || (sb->buf[n]==CHAR_CR && sb->buf[m]!=CHAR_LF)) {
3562  sb->npoint = m;
3563  break;
3564  }
3565  n = m;
3566  }
3567  }
3568 
3569  return pp;
3570 }
#define JBXL_ERROR
エラー
Definition: jbxl_state.h:34
unsigned char * get_ringBuffer(ringBuffer *rb, int sz)
リングバッファからデータを得る.要 free()
Definition: tools.c:3383
char * chomp(char *buf)
最初の改行コード以降を無効にする.
Definition: tools.c:921

References CHAR_CR, CHAR_LF, chomp(), get_ringBuffer(), JBXL_ERROR, JBXL_NORMAL, and len.

Referenced by fgets_mstream(), ssl_recv_mstream(), ssl_recv_mstream_Buffer(), ssl_tcp_recv_mstream(), ssl_tcp_recv_mstream_Buffer(), tcp_recv_mstream(), and tcp_recv_mstream_Buffer().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_ringBuffer()

unsigned char* get_ringBuffer ( ringBuffer rb,
int  sz 
)

unsigned char* get_ringBuffer(ringBuffer* rb, int sz)

リングバッファ rb から szバイトのデータを取り出す.
返されたデータは free()する必要がある.

Parameters
[in]rbリングバッファへのポインタ
[out]rbstate JBXL_NORMAL: バッファは正常状態.JBXL_ERROR: バッファは異常な状態にある.
sz取り出すバイト数.
Return values
NULL以外取り出したデータへのポインタ.データサイズは sz + 1.要 free
NULLデータ取得失敗.現在有効なデータサイズはszより小さい.または単に失敗した.

Definition at line 3383 of file tools.c.

3384 {
3385  unsigned char* pp;
3386 
3387  if (rb==NULL) return NULL;
3388  if (rb->buf==NULL) return NULL;
3389  if (sz>rb->datasz) return NULL;
3390 
3391  pp = (unsigned char*)malloc(sz+1);
3392  if (pp==NULL) return NULL;
3393  memset(pp, 0, sz+1);
3394 
3395  if (rb->spoint+sz<=rb->bufsz) {
3396  memcpy(pp, &(rb->buf[rb->spoint]), sz);
3397  rb->spoint = rb->spoint + sz;
3398  if (rb->spoint==rb->bufsz) rb->spoint = 0;
3399  }
3400  else {
3401  memcpy(pp, &(rb->buf[rb->spoint]), rb->bufsz-rb->spoint);
3402  memcpy(&(pp[rb->bufsz-rb->spoint]), rb->buf, sz-(rb->bufsz-rb->spoint));
3403  rb->spoint = rb->spoint + sz - rb->bufsz;
3404  }
3405 
3406  rb->datasz -= sz;
3407  return pp;
3408 }
int datasz
保存されているデータの全体の長さ
Definition: tools.h:160
int spoint
バッファデータの開始点
Definition: tools.h:158

References ringBuffer::buf, ringBuffer::bufsz, ringBuffer::datasz, and ringBuffer::spoint.

Referenced by get_mstream().

Here is the caller graph for this function:

◆ get_seq_data()

char* get_seq_data ( char *  buf,
int *  ptr 
)

char* get_seq_data(char* buf, int* ptr)

文字型データ bufのバッファ内の行データをシーケンシャルに取り出す.

改行コードは削除される.連続して呼び出す場合,一番最初は *ptrに 0を設定し,以後は *ptrの内容は変えない.
取り出した行を char型変数のバッファに格納して返す.
バッファの最後が '\0' で終わっている場合,バッファを越えて行を読もうとした時は NULL を返す.
'\0' で終わっていない場合,バッファが何処で終わりかを知る事は(簡単な方法では)できない.

返されたデータは free() する必要がある.

Parameters
[in]buf操作対象文の字列型データ(含む改行)
[in]ptr読み込みを開始するデータの位置(バイト).
[out]ptr次のデータが始まる位置(バイト).
Returns
指定されたポインタ以下の一行分の文字列.改行は含まない.要 free

Definition at line 529 of file tools.c.

530 {
531  int pos, cnt;
532  char* ret = NULL;
533 
534  if (buf==NULL || buf[*ptr]=='\0') return NULL;
535 
536  pos = *ptr;
537  while (buf[*ptr]!=CHAR_LF && buf[*ptr]!=CHAR_CR && buf[*ptr]!='\0') (*ptr)++;
538  cnt = *ptr - pos;
539 
540  if (cnt>=0) {
541  ret = (char*)malloc(cnt+1);
542  if (ret==NULL) return NULL;
543 
544  int i;
545  for(i=0; i<cnt; i++) ret[i] = buf[pos+i];
546  ret[cnt] = '\0';
547  }
548 
549  while (buf[*ptr]==CHAR_LF || buf[*ptr]==CHAR_CR) (*ptr)++;
550  return ret;
551 }

References buf, CHAR_CR, and CHAR_LF.

◆ get_used_memory()

long unsigned int get_used_memory ( void  )

unsigned long int get_used_memory(void)

使用中のメモリサイズを得る.

Definition at line 3703 of file tools.c.

3704 {
3705  struct sysinfo info;
3706  sysinfo(&info);
3707 
3708  // キャッシュサイズが引けていない.
3709  unsigned long int mem = info.totalram - info.freeram - info.bufferram - info.sharedram;
3710  return mem*info.mem_unit/1024;
3711 }

Referenced by memory_check(), and memory_check_start().

Here is the caller graph for this function:

◆ guid2uuid()

unsigned char* guid2uuid ( unsigned char *  p)

unsigned char* guid2uuid(unsigned char* p)

テキストのGUID をバイナリのUUID に変換する.要 free()
入力が GUIDの形式でない時は,処理結果は保証されない.

Parameters
pテキストの GUID
Returns
バイナリの UUIDへのポインタ.128bit. 要 free

Definition at line 3655 of file tools.c.

3656 {
3657  int i, j;
3658  unsigned char* uuid;
3659 
3660  if (p==NULL) return NULL;
3661 
3662  uuid = (unsigned char*)malloc(16);
3663  if (uuid==NULL) return NULL;
3664  memset(uuid, 0, 16);
3665 
3666  i = j = 0;
3667  while (p[i]!='\0' && j<16) {
3668  if (p[i]!='-' && p[i+1]!='\0') {
3669  unsigned char hb, lb;
3670 
3671  if (p[i]>='0' && p[i]<='9') hb = p[i] - '0';
3672  else if (p[i]>='a' && p[i]<='f') hb = p[i] - 'a' + 10;
3673  else if (p[i]>='A' && p[i]<='F') hb = p[i] - 'A' + 10;
3674  else hb = '\0';
3675 
3676  if (p[i+1]>='0' && p[i+1]<='9') lb = p[i+1] - '0';
3677  else if (p[i+1]>='a' && p[i+1]<='f') lb = p[i+1] - 'a' + 10;
3678  else if (p[i+1]>='A' && p[i+1]<='F') lb = p[i+1] - 'A' + 10;
3679  else lb = '\0';
3680 
3681  uuid[j] = (hb<<4) + lb;
3682  i++;
3683  j++;
3684  }
3685  i++;
3686  }
3687 
3688  return uuid;
3689 }

◆ hexstr2i()

int hexstr2i ( const char *  str)

int hexstr2i(const char* str)

16進数の文字列を整数に変換する.

空白は無視する.空白以外の16進数でない文字が出現したら,そこで変換を止める

Parameters
str整数に変換する 16進の文字列
Returns
変換された整数

Definition at line 1706 of file tools.c.

1707 {
1708  int i, ret = 0;
1709  if (str==NULL) return ret;
1710 
1711  int len = (int)strlen(str);
1712 
1713  for (i=0; i<len; i++) {
1714  if (str[i]>='0' && str[i]<='9') {
1715  ret = ret*16;
1716  ret += (int)(str[i] - '0');
1717  }
1718  else if (str[i]>='A' && str[i]<='F') {
1719  ret = ret*16;
1720  ret += (int)(str[i] - 'A') + 10;
1721  }
1722  else if (str[i]>='a' && str[i]<='f') {
1723  ret = ret*16;
1724  ret += (int)(str[i] - 'a') + 10;
1725  }
1726  else if (str[i]!=' ') {
1727  break;
1728  }
1729  }
1730 
1731  return ret;
1732 }

References len.

Referenced by get_chunked_size().

Here is the caller graph for this function:

◆ ignore_sigterm_child()

void ignore_sigterm_child ( void  )

void ignore_sigterm_child()

以後 child プロセスの終了を無視する.

Definition at line 3808 of file tools.c.

3809 {
3810  struct sigaction sa;
3811 
3812  memset(&sa, 0, sizeof(sa));
3813  sa.sa_handler = SIG_IGN;
3814  sa.sa_flags = 0;
3815  sigemptyset(&sa.sa_mask);
3816  sigaction(SIGCHLD, &sa, NULL);
3817 }

◆ init_rand()

void init_rand ( void  )

void init_rand(void)

/dev/urandom から乱数の系列を初期化する

/dev/urandom が読めない場合は,呼び出された時の時間(秒数)によって乱数の系列を初期化する.

Attention
Windows では使用できない

Definition at line 1747 of file tools.c.

1748 {
1749  FILE* fp;
1750  unsigned int seed;
1751  size_t sz;
1752  UNUSED(sz);
1753 
1754  fp = fopen("/dev/urandom", "rb");
1755  if (fp==NULL) {
1756  srand(time(NULL));
1757  return;
1758  }
1759  sz = fread(&seed, sizeof(unsigned int), 1, fp);
1760  fclose(fp);
1761 
1762  srand(seed);
1763 }

References UNUSED.

◆ init_ringBuffer()

ringBuffer init_ringBuffer ( void  )

ringBuffer init_ringBuffer()

初期化された ringBuffer変数を返す.

Returns
期化された ringBuffer変数
See also
ringBuffer

Definition at line 3251 of file tools.c.

3252 {
3253  ringBuffer rb;
3254 
3255  memset(&rb, 0, sizeof(ringBuffer));
3256  rb.state = JBXL_NORMAL;
3257 
3258  return rb;
3259 }

References JBXL_NORMAL, and ringBuffer::state.

◆ int_from_big_endian()

int int_from_big_endian ( void *  ptr)

int int_from_big_endian(void* ptr)

Big Endian形式で格納されている int型の値を取り出す.

Parameters
ptr変数が格納されているメモリへのポインタ
Returns
取り出した int型の値

Definition at line 300 of file tools.c.

301 {
302  int ret = *((int*)ptr);
303 
305  if (HostEndian==LITTLE_ENDIAN) reverse_str((uByte*)(&ret), 4);
306  return ret;
307 }

References check_endian(), HostEndian, LITTLE_ENDIAN, reverse_str(), and UNKNOWN_ENDIAN.

Referenced by read_shape_index_file(), and read_shape_main_file().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ int_from_little_endian()

int int_from_little_endian ( void *  ptr)

int int_from_little_endian(void* ptr)

Little Endian形式で格納されている int型の値を取り出す.

Parameters
ptr変数が格納されているメモリへのポインタ
Returns
取り出した int型の値

Definition at line 192 of file tools.c.

193 {
194  int ret = *((int*)ptr);
195 
197  if (HostEndian==BIG_ENDIAN) reverse_str((uByte*)(&ret), 4);
198  return ret;
199 }

References BIG_ENDIAN, check_endian(), HostEndian, reverse_str(), and UNKNOWN_ENDIAN.

Referenced by draw_shape_polygon(), read_shape_index_file(), and read_shape_main_file().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_big_endian()

int is_big_endian ( void  )

int is_big_endian(void)

エンディアンの動的チェック

一度呼び出すと,大域変数 HostEndianLITTLE_ENDIANBIG_ENDIAN が設定される.

Return values
TRUEBig Endian
FALSELittle Endian
See also
HostEndian, is_little_endian()

Definition at line 114 of file tools.c.

115 {
116  unsigned char x[] = {0x00, 0x01};
117 
118  if (HostEndian==BIG_ENDIAN) return TRUE;
119 
120  else if (HostEndian==LITTLE_ENDIAN) return FALSE;
121 
122  else {
123  unsigned short* xx = (unsigned short*)x;
124  if (*xx==1) {
126  return TRUE;
127  }
128  else {
130  return FALSE;
131  }
132  }
133 }

References BIG_ENDIAN, FALSE, HostEndian, LITTLE_ENDIAN, and TRUE.

Referenced by get_tiff_ifd().

Here is the caller graph for this function:

◆ is_little_endian()

int is_little_endian ( void  )

int is_little_endian(void)

エンディアンの動的チェック

一度呼び出すと,大域変数 HostEndianLITTLE_ENDIANBIG_ENDIAN が設定される.

Return values
TRUELittle Endian
FALSEBig Endian
See also
HostEndian, is_big_endian()

Definition at line 80 of file tools.c.

81 {
82  unsigned char x[] = {0x01, 0x00};
83 
84  if (HostEndian==LITTLE_ENDIAN) return TRUE;
85 
86  else if (HostEndian==BIG_ENDIAN) return FALSE;
87 
88  else {
89  unsigned short* xx = (unsigned short*)x;
90  if (*xx==1) {
92  return TRUE;
93  }
94  else {
96  return FALSE;
97  }
98  }
99 }

References BIG_ENDIAN, FALSE, HostEndian, LITTLE_ENDIAN, and TRUE.

Referenced by check_endian(), get_tiff_ifd(), ntohull(), and read_user_data().

Here is the caller graph for this function:

◆ is_number()

int is_number ( unsigned char *  str)

int is_number(unsigned char* str)

文字列が数字かどうか反転する.

Parameters
検査する文字列
Returns
0: 数字でない.1: 整数.2: 小数点付き数字.

Definition at line 1394 of file tools.c.

1395 {
1396  if (str==NULL) return 0;
1397  int i, len = (int)strlen((char*)str);
1398 
1399  int cnt = 0;
1400  for (i=0; i<len; i++) {
1401  if (str[i]=='.') cnt += 1;
1402  else if (str[i]<'0' || str[i]>'9') return 0;
1403  }
1404  if (cnt>1) return 0;
1405  else if (cnt>0) return 2;
1406  return 1;
1407 }

References len.

Referenced by json_array_parse(), and json_parse_prop().

Here is the caller graph for this function:

◆ isNull()

int isNull ( void *  p)

int isNull(void* p)

ポインタが NULLかどうかを検査する.
Windowsの場合,無効ポインタも検出する.

Parameters
p検査するポインタ.
Return values
TRUEポインタがNULL,または無効(Windowsの場合)
FALSEポインタはNULLではなく有効(Windowsの場合)である.
Attention
JunkBox_LIb++ の場合はこの関数ではなく,inline型の isNull() が使用される.

Definition at line 51 of file tools.c.

52 {
53  if (p==NULL) return TRUE;
54 
55 #ifdef WIN32
56  if (p==WIN_DD_NULL) return TRUE;
57 #endif
58 
59  return FALSE;
60 }

References FALSE, and TRUE.

◆ itostr()

char* itostr ( int  n)

char* itostr(int n)

int型 nを文字列にして返す.

Parameters
n文字列に変換する値
Returns
変換された文字列.free() してはいけない.

Definition at line 1420 of file tools.c.

1421 {
1422  memset(_ToSTR, 0, LDATA);
1423  snprintf(_ToSTR, LDATA-1, "%d", n);
1424  return _ToSTR;
1425 }

References _ToSTR, and LDATA.

◆ itostr_ts()

char* itostr_ts ( int  n)

char* itostr_ts(int n)

int型 nを文字列にして返す.Thread Safe

Parameters
n文字列に変換する値
Returns
変換された文字列.要 free.

Definition at line 1532 of file tools.c.

1533 {
1534  char* str = NULL;
1535  str = (char*)malloc(LDATA);
1536  if (str==NULL) return NULL;
1537 
1538  memset(str, 0, LDATA);
1539  snprintf(str, LDATA-1, "%d", n);
1540  return str;
1541 }

References LDATA.

Referenced by _tcp_bind(), _tcp_bind_setopt(), _tcp_client_bind_socket(), _tcp_client_socket(), _tcp_connect(), _tcp_server_bind(), _tcp_server_bind_setopt(), _tcp_server_socket(), _tcp_server_socket_setopt(), _udp_bind(), _udp_bind_setopt(), _udp_client_socket(), _udp_server_socket(), _udp_server_socket_setopt(), llsd_bin_main_parse(), make_xml_attr_byint(), open_ldap_connection(), recv_http_Buffer(), and recv_http_file().

Here is the caller graph for this function:

◆ kanji_convert()

void kanji_convert ( unsigned char *  mesg)

void kanji_convert(unsigned char* mesg)

大域変数 KnjiCodeに従って漢字コードを変換する.

Parameters
[in,out]mesg変換する文字列を持つ unsigned char*型データ.内容が書き換えられる.
Attention
現在は KanjiCodeが SJISの場合のみ EUCを SJISに変換する.
See also
KanjiCode

Definition at line 2630 of file tools.c.

2631 {
2632  if (KanjiCode==CODE_SJIS) {
2633  kanji_convert_euc2sjis(mesg);
2634  }
2635 }
int KanjiCode
システムの漢字コード
Definition: tools.c:20
void kanji_convert_euc2sjis(unsigned char *mesg)
EUCをSJISに変換する.
Definition: tools.c:2645
#define CODE_SJIS
Definition: tools.h:85

References CODE_SJIS, kanji_convert_euc2sjis(), and KanjiCode.

Here is the call graph for this function:

◆ kanji_convert_euc2sjis()

void kanji_convert_euc2sjis ( unsigned char *  mesg)

void kanji_convert_euc2sjis(unsigned char* mesg)

EUCをSJISに変換する.

Parameters
[in,out]mesg変換する文字列を持つ unsigned char*型データ.内容が書き換えられる.

Definition at line 2645 of file tools.c.

2646 {
2647  int i = 0;
2648  while(mesg[i]!='\0' && mesg[i+1]!='\0'){
2649  if (mesg[i]>=0xa1 && mesg[i]<=0xfe){ // EUC
2650  euc2sjis(&mesg[i], &mesg[i+1]);
2651  i = i + 2;
2652  }
2653  else i++;
2654  }
2655 }
void euc2sjis(unsigned char *c1, unsigned char *c2)
EUC -> SJIS.
Definition: tools.c:2688

References euc2sjis().

Referenced by kanji_convert().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ kanji_convert_sjis2euc()

void kanji_convert_sjis2euc ( unsigned char *  mesg)

void kanji_convert_sjis2euc(unsigned char* mesg)

SJISをEUCに変換する.

Parameters
[in,out]mesg変換する文字列を持つ unsigned char*型データ.内容が書き換えられる.

Definition at line 2665 of file tools.c.

2666 {
2667  int i = 0;
2668  while(mesg[i]!='\0' && mesg[i+1]!='\0'){
2669  // if文が変則的なのは,コンパイラで警告が出るため (GCC) 3.3.2 20031218
2670  if ((mesg[i]>=0x81 && mesg[i]<=0x9f) ||
2671  (mesg[i]>=0xe0 && mesg[i]<=0xfe) || mesg[i]==0xff) { // SJIS
2672  sjis2euc(&mesg[i], &mesg[i+1]);
2673  i = i + 2;
2674  }
2675  else i++;
2676  }
2677 }
void sjis2euc(unsigned char *c1, unsigned char *c2)
SJIS -> EUC.
Definition: tools.c:2717

References sjis2euc().

Here is the call graph for this function:

◆ lltostr()

char* lltostr ( long long int  n)

char* lltostr(long long int n)

long long int型 nを文字列にして返す.

Parameters
n文字列に変換する値
Returns
変換された文字列.free() してはいけない.

Definition at line 1468 of file tools.c.

1469 {
1470  memset(_ToSTR, 0, LDATA);
1471  snprintf(_ToSTR, LDATA-1, "%lld", n);
1472  return _ToSTR;
1473 }

References _ToSTR, and LDATA.

◆ lltostr_ts()

char* lltostr_ts ( long long int  n)

char* lltostr_ts(long long int n)

long long int型 nを文字列にして返す.Thread Safe

Parameters
n文字列に変換する値
Returns
変換された文字列.要 free.

Definition at line 1592 of file tools.c.

1593 {
1594  char* str = NULL;
1595  str = (char*)malloc(LDATA);
1596  if (str==NULL) return NULL;
1597 
1598  memset(str, 0, LDATA);
1599  snprintf(str, LDATA-1, "%lld", n);
1600  return str;
1601 }

References LDATA.

◆ ltostr()

char* ltostr ( long int  n)

char* ltostr(long int n)

long int型 nを文字列にして返す.

Parameters
n文字列に変換する値
Returns
変換された文字列.free() してはいけない.

Definition at line 1436 of file tools.c.

1437 {
1438  memset(_ToSTR, 0, LDATA);
1439  snprintf(_ToSTR, LDATA-1, "%ld", n);
1440  return _ToSTR;
1441 }

References _ToSTR, and LDATA.

◆ ltostr_ts()

char* ltostr_ts ( long int  n)

char* ltostr_ts(long int n)

long int型 nを文字列にして返す.Thread Safe

Parameters
n文字列に変換する値
Returns
変換された文字列.要 free.

Definition at line 1552 of file tools.c.

1553 {
1554  char* str = NULL;
1555  str = (char*)malloc(LDATA);
1556  if (str==NULL) return NULL;
1557 
1558  memset(str, 0, LDATA);
1559  snprintf(str, LDATA-1, "%ld", n);
1560  return str;
1561 }

References LDATA.

◆ make_ringBuffer()

ringBuffer make_ringBuffer ( int  sz)

ringBuffer make_ringBuffer(int sz)

バッファ部が存在するリングバッファを作り出す. バッファ部は free()する必要がある.

Parameters
szリングバッファのバッファ部のサイズ
Returns
作成された ringBuffer変数.バッファ部は 要 free

Definition at line 3271 of file tools.c.

3272 {
3273  ringBuffer rb;
3274 
3275  memset(&rb, 0, sizeof(ringBuffer));
3276 
3277  if (sz>0) {
3278  rb.buf = (unsigned char*)malloc(sz);
3279  if (rb.buf==NULL) return rb;
3280  memset(rb.buf, 0, sz);
3281  rb.bufsz = sz;
3282  rb.state = JBXL_NORMAL;
3283  }
3284 
3285  return rb;
3286 }

References ringBuffer::buf, ringBuffer::bufsz, JBXL_NORMAL, and ringBuffer::state.

◆ memory_check()

long unsigned int memory_check ( void  )

Definition at line 3735 of file tools.c.

3736 {
3737  return get_used_memory() - UsedMemoryBase;
3738 }
unsigned long int UsedMemoryBase
メモリチェック用
Definition: tools.c:23
unsigned long int get_used_memory(void)
使用中のメモリサイズを得る.
Definition: tools.c:3703

References get_used_memory(), and UsedMemoryBase.

Here is the call graph for this function:

◆ memory_check_start()

void memory_check_start ( void  )

Definition at line 3729 of file tools.c.

3730 {
3732 }

References get_used_memory(), and UsedMemoryBase.

Here is the call graph for this function:

◆ mkdirp()

int mkdirp ( const char *  path,
mode_t  mode 
)

Definition at line 2511 of file tools.c.

2512 {
2513  if (path==NULL) return JBXL_ARGS_ERROR;
2514 
2515  long unsigned int lpath = (long unsigned int)strlen(path);
2516  char* file_name = (char*)malloc(lpath + 1);
2517  memcpy(file_name, path, lpath);
2518  file_name[lpath] = '\0';
2519  //
2520  long unsigned int size = 0;
2521  int mark = 1;
2522 #ifdef WIN32
2523  if (file_name[1]==':') mark = 2; // ex.) "D:/abc/xyz"
2524 #endif
2525 
2526  char* wrk = (char*)malloc(lpath + 1);
2527  while (size < lpath) {
2528  memcpy(wrk, file_name, lpath + 1);
2529  int dirs = 0;
2530  long unsigned int ptr = 0;
2531  for (ptr=0; ptr<=lpath; ptr++) {
2532  if (wrk[ptr]=='/') dirs++;
2533  if (mark==dirs) {
2534  wrk[ptr] = '\0';
2535  struct stat stbuf;
2536  int ret = stat(wrk, &stbuf);
2537  if (ret>=0) {
2538  if (!(stbuf.st_mode & S_IFDIR)) {
2539  return JBXL_FILE_EXIST_ERROR;
2540  }
2541  break;
2542  }
2543  ret = mkdir(wrk, mode);
2544  if (ret<0) return JBXL_DIR_MAKE_ERROR;
2545  break;
2546  }
2547  size = ptr;
2548  }
2549  mark++;
2550  }
2551  free(wrk);
2552  return JBXL_NORMAL;
2553 }
#define JBXL_DIR_MAKE_ERROR
ディレクトリ作成エラー
Definition: jbxl_state.h:53

References JBXL_ARGS_ERROR, JBXL_DIR_MAKE_ERROR, JBXL_FILE_EXIST_ERROR, and JBXL_NORMAL.

Referenced by extract_tTar().

Here is the caller graph for this function:

◆ new_ringBuffer()

ringBuffer* new_ringBuffer ( int  sz)

ringBuffer* new_ringBuffer(int sz)

リングバッファ型変数を生成する.
返されたデータは del_ringBuffer() する必要がある.

Returns
空のリングバッファ変数.要 free
See also
ringBuffer, del_ringBuffer()

Definition at line 3205 of file tools.c.

3206 {
3207  ringBuffer* rb;
3208 
3209  rb = (ringBuffer*)malloc(sizeof(ringBuffer));
3210  if (rb==NULL) return NULL;
3211  memset(rb, 0, sizeof(ringBuffer));
3212  rb->state = JBXL_NORMAL;
3213 
3214  if (sz>0) {
3215  rb->buf = (unsigned char*)malloc(sz);
3216  if (rb->buf==NULL) return rb;
3217  memset(rb->buf, 0, sz);
3218  rb->bufsz = sz;
3219  }
3220  return rb;
3221 }

References ringBuffer::buf, ringBuffer::bufsz, JBXL_NORMAL, and ringBuffer::state.

◆ ntohull()

long unsigned long int ntohull ( long unsigned long int  s)

◆ numbering_name()

char* numbering_name ( const char *  fmt,
int  n 
)

char* numbering_name(const char* fmt, int n)

フォーマット fmtに従って,nを含む文字列を作り出す. 返されたデータは free()する必要がある.

Parameters
fmtフォーマット用文字列.ex. "%d %f\n" see printf()
n文字に変換する整数.
Returns
出力された文字列.要 free
See also
printf()

Definition at line 2599 of file tools.c.

2600 {
2601  int len;
2602  char fname[LNAME], *fo;
2603 
2604  memset(fname, 0, LNAME);
2605  snprintf(fname, LNAME-1, fmt, n);
2606  len = (int)strlen(fname);
2607 
2608  fo = (char*)malloc(len+1);
2609  if (fo==NULL) return NULL;
2610 
2611  memset(fo, 0, len+1);
2612  strncpy(fo, fname, len);
2613  return fo;
2614 }
#define LNAME
Definition: common.h:153

References len, and LNAME.

◆ open_errfile()

void open_errfile ( void  )

void open_errfile(void)

デフォルトのエラーファイルをオープンする

Definition at line 3977 of file tools.c.

3978 {
3979  if (FP_ErrFile!=NULL) return;
3980 
3981  FP_LogFile = fopen(JBXL_ERR_FILE, "a");
3982  return;
3983 }
#define JBXL_ERR_FILE
デフォルトのエラーファイル
Definition: tools.h:444

References FP_ErrFile, FP_LogFile, and JBXL_ERR_FILE.

◆ open_logfile()

void open_logfile ( void  )

void open_logfile(void)

デフォルトのログファイルをオープンする

Definition at line 3902 of file tools.c.

3903 {
3904  if (FP_LogFile!=NULL) return;
3905 
3906  FP_LogFile = fopen(JBXL_LOG_FILE, "a");
3907  return;
3908 }
#define JBXL_LOG_FILE
デフォルトのログファイル
Definition: tools.h:443

References FP_LogFile, and JBXL_LOG_FILE.

◆ pack_char_len()

char* pack_char_len ( char *  mesg,
char  cc,
int  len 
)

char* pack_char(char* mesg, char cc)

文字列中及び,先頭のcc(複数),終わりのcc(複数),CR, LF を削除

タブは空白に変換.メッセージ中の連続する cc は 1個に変換. 返されたデータは free()する必要がある.

CR, LF も削除(無視)されるので注意.

Parameters
mesg操作対象の文字列
cc削除する文字
Returns
変換後の文字列.要 free char* pack_char_len(char* mesg, char cc, int len)

文字列の一部の先頭のcc(複数),終わりのcc(複数),CR, LF を削除

タブは空白に変換.メッセージ中の連続する cc は 1個に変換. 返されたデータは free()する必要がある.

CR, LF も削除(無視)されるので注意.

Parameters
mesg操作対象の文字列
cc削除する文字
len操作する文字列の長さ
Returns
変換後の文字列.要 free

Definition at line 1154 of file tools.c.

1155 {
1156  int i, j;
1157  int sf = OFF; // 連続 cc 用のフラグ
1158  int ff = ON; // 先頭の cc を無視するためのフラグ
1159  char* pp;
1160 
1161  if (mesg==NULL) return NULL;
1162 
1163  if (len==0) return NULL;
1164  if (len<0) len = (int)strlen(mesg);
1165  pp = (char*)malloc(len+1);
1166  if (pp==NULL) return NULL;
1167  memset(pp, 0, len+1);
1168 
1169  i = j = 0;
1170  while(mesg[i]!='\0' && i<len) {
1171  if (mesg[i]==CHAR_TAB) mesg[i] = ' ';
1172  if (mesg[i]!=CHAR_CR && mesg[i]!=CHAR_LF) { // CR LF を読み飛ばす.
1173  if (mesg[i]==cc) {
1174  if (sf==OFF) {
1175  sf = ON;
1176  if (ff==ON) ff = OFF;
1177  else pp[j++] = mesg[i];
1178  }
1179  }
1180  else {
1181  sf = ff = OFF;
1182  pp[j++] = mesg[i];
1183  }
1184  }
1185  i++;
1186  }
1187  pp[j] = '\0';
1188 
1189  // 末尾の cc を削除
1190  i = (int)strlen(pp) - 1;
1191  while(i>=0) {
1192  if (pp[i]==cc) i--;
1193  else break;
1194  }
1195  pp[i+1] = '\0';
1196 
1197  return pp;
1198 }
#define OFF
Definition: common.h:231
#define ON
Definition: common.h:230
#define CHAR_TAB
タブ
Definition: tools.h:80

References CHAR_CR, CHAR_LF, CHAR_TAB, len, OFF, and ON.

◆ pack_head_tail_char()

char* pack_head_tail_char ( char *  mesg,
char  cc 
)

char* pack_head_tail_char(char* mesg, char cc)

文字列の先頭のcc(複数),終わりのcc(複数),TAB, CR, LF を削除

文字列の先頭,終わり部分でない場所にある ccは削除されない. 返されたデータは free()する必要がある.

Parameters
mesg操作対象の文字列
cc削除する文字
Returns
変換後の文字列.要 free

Definition at line 1092 of file tools.c.

1093 {
1094  int sz;
1095  char* ps;
1096  char* pe;
1097  char* pp;
1098 
1099  if (mesg==NULL) return NULL;
1100 
1101  ps = mesg;
1102  while(*ps==cc || *ps==CHAR_TAB || *ps==CHAR_LF || *ps==CHAR_CR) ps++;
1103  pe = ps;
1104  while(*pe!='\0') pe++;
1105  pe--;
1106  while(*pe==cc || *pe==CHAR_TAB || *pe==CHAR_LF || *pe==CHAR_CR) pe--;
1107 
1108  sz = (int)(pe - ps) + 1;
1109  pp = (char*)malloc((size_t)(sz + 1));
1110  memcpy(pp, ps, sz);
1111  pp[sz] = '\0';
1112 
1113  return pp;
1114 }

References CHAR_CR, CHAR_LF, and CHAR_TAB.

Referenced by xml_parse_content(), and xml_parse_end_node().

Here is the caller graph for this function:

◆ print_16x()

void print_16x ( FILE *  fp,
unsigned char *  mesg,
int  n 
)

void print_16x(FILE* fp, unsigned char* mesg, int n)

デバッグ用 16進一行出力.

mesgの nバイトの16進を一行,空白なしで表示する.n<0 の場合は 文字列とみなす.

Parameters
fp出力するファイルへのポインタ.NULLの場合は stderr
mesg表示するデータ.
n表示するバイト数

Definition at line 4228 of file tools.c.

4229 {
4230  int i, len;
4231 
4232  if (fp==NULL) fp = stderr;
4233 
4234  if (n<0) len = (int)strlen((const char*)mesg);
4235  else len = n;
4236 
4237  for (i=0; i<len; i++) {
4238  fprintf(fp, "%02x", mesg[i]);
4239  }
4240  fprintf(fp, "\n");
4241 }

References len.

◆ print_errfile()

void print_errfile ( const char *  fmt,
  ... 
)

void print_errfile(const char* fmt, ...)

デフォルトのエラーファイルにデータを書き込む

Definition at line 4007 of file tools.c.

4008 {
4009  char* nfmt;
4010  int len;
4011  int slfopn = FALSE;
4012 
4013  //
4014  if (FP_ErrFile==NULL) {
4015  FP_ErrFile = fopen(JBXL_ERR_FILE, "a");
4016  if (FP_ErrFile==NULL) return;
4017  slfopn = TRUE;
4018  }
4019 
4020  va_list args;
4021  va_start(args, fmt);
4022 
4023  len = (int)strlen(fmt);
4024  nfmt = (char*)malloc(len + 2);
4025  if (nfmt==NULL) return;
4026 
4027  strncpy(nfmt, fmt, len);
4028  nfmt[len] = '\n';
4029  nfmt[len+1] = '\0';
4030 
4031  vfprintf(FP_ErrFile, nfmt, args);
4032  fflush(FP_ErrFile);
4033  free(nfmt);
4034 
4035  va_end(args);
4036 
4037  //
4038  if (slfopn && FP_ErrFile!=NULL) {
4039  fclose(FP_ErrFile);
4040  FP_ErrFile = NULL;
4041  }
4042 
4043  return;
4044 }

References FALSE, FP_ErrFile, JBXL_ERR_FILE, len, and TRUE.

◆ print_escape()

void print_escape ( const char *  fmt,
char *  mesg 
)

void print_escape(const char* fmt, const char* mesg)

エスケープ文字を含むメッセージの出力.(stderr)

現在は CR, LF のみ \r, \n に変換する.see change_esc()

Parameters
fmt出力フォーマット.printf() に準拠.
mesgエスケープ文字を含む文字列.
See also
change_esc(), printf()

Definition at line 4125 of file tools.c.

4126 {
4127  char* pp;
4128 
4129  if (fmt==NULL || mesg==NULL) return;
4130 
4131  pp = change_esc(mesg);
4132  if (pp==NULL) return;
4133 
4134  PRINT_MESG(fmt, pp);
4135  free(pp);
4136 }
char * change_esc(char *mesg)
文字列中の CR, LF を \r, \n に変換する.要 free()
Definition: tools.c:1210
#define PRINT_MESG
環境依存用の出力関数.print_message()
Definition: tools.h:475

References change_esc(), and PRINT_MESG.

Here is the call graph for this function:

◆ print_logfile()

void print_logfile ( const char *  fmt,
  ... 
)

void print_logfile(const char* fmt, ...)

デフォルトのログファイルにデータを書き込む

Definition at line 3932 of file tools.c.

3933 {
3934  char* nfmt;
3935  int len;
3936  int slfopn = FALSE;
3937 
3938  //
3939  if (FP_LogFile==NULL) {
3940  FP_LogFile = fopen(JBXL_LOG_FILE, "a");
3941  if (FP_LogFile==NULL) return;
3942  slfopn = TRUE;
3943  }
3944 
3945  va_list args;
3946  va_start(args, fmt);
3947 
3948  len = (int)strlen(fmt);
3949  nfmt = (char*)malloc(len + 2);
3950  if (nfmt==NULL) return;
3951 
3952  strncpy(nfmt, fmt, len);
3953  nfmt[len] = '\n';
3954  nfmt[len+1] = '\0';
3955 
3956  vfprintf(FP_LogFile, nfmt, args);
3957  fflush(FP_LogFile);
3958  free(nfmt);
3959 
3960  va_end(args);
3961 
3962  //
3963  if (slfopn && FP_LogFile!=NULL) {
3964  fclose(FP_LogFile);
3965  FP_LogFile = NULL;
3966  }
3967 
3968  return;
3969 }

References FALSE, FP_LogFile, JBXL_LOG_FILE, len, and TRUE.

◆ print_message()

void print_message ( const char *  fmt,
  ... 
)

void print_message(const char* fmt, ...)

バッファリング無しのメッセージ出力(stderr)

Parameters
fmt出力フォーマット.printf() に準拠.
See also
printf()

Definition at line 4055 of file tools.c.

4056 {
4057  char* nfmt;
4058  int len;
4059 
4060  va_list args;
4061  va_start(args, fmt);
4062 
4063  len = (int)strlen(fmt);
4064  nfmt = (char*)malloc(len + 1);
4065  if (nfmt==NULL) return;
4066 
4067  strncpy(nfmt, fmt, len);
4068  nfmt[len] = '\0';
4069 
4070  vfprintf(stderr, nfmt, args);
4071  fflush(stderr);
4072  free(nfmt);
4073 
4074  va_end(args);
4075 
4076  return;
4077 }

References len.

◆ put_mstream()

int put_mstream ( mstream sb,
unsigned char *  mesg 
)

int put_mstream(mstream* sb, unsigned char* mesg)

メッセージ(文字列)ストリーム sb へメッセージ(の一部)を格納する.
ここで,メッセージとは \r\n, \r または \n で区切られている文字列でのことである.

Parameters
[in]sbメッセージストリームへのポインタ
[out]sbstate JBXL_NORMAL: ストリームは正常状態.JBXL_ERROR: ストリームは異常な状態にある.
mesg格納するメッセージ,またはその一部
Return values
0以上書き込んだバイト数(CRLFを含む)
JBXL_ARGS_ERROR引数にNULLのデータがある.
JBXL_TOOLS_BUF_ERRORバッファ(データ格納)部の領域がない.
JBXL_TOOLS_BUFSZ_ERRORバッファ(データ格納)部の大きさがたりない.

Definition at line 3491 of file tools.c.

3492 {
3493  int i, n, m, cc, np=0, len;
3494 
3495  if (sb==NULL) return JBXL_ARGS_ERROR;
3496  sb->state = JBXL_NORMAL;
3497  if (mesg==NULL) return JBXL_ARGS_ERROR;
3498  if (sb->buf==NULL) return JBXL_TOOLS_BUF_ERROR;
3499 
3500  len = (int)strlen((const char*)mesg);
3501  for (i=0, n=0, m=0; i<len; i++) {
3502  if (mesg[i]==CHAR_LF || (mesg[i]==CHAR_CR && mesg[i+1]!=CHAR_LF)) {
3503  if (m==0) m = i;
3504  n++;
3505  }
3506  }
3507  if (sb->datano==0 && n>=1) np = (sb->epoint + m + 1) % sb->bufsz;
3508 
3509  cc = put_ringBuffer(sb, mesg, len);
3510  if (cc>=0) {
3511  if (sb->datano==0 && n>=1) sb->npoint = np;
3512  sb->datano += n;
3513  }
3514 
3515  if (cc<0) sb->state = JBXL_ERROR;
3516  return cc;
3517 }
#define JBXL_TOOLS_BUF_ERROR
バッファ(データ格納)部の領域がない
Definition: jbxl_state.h:56
int put_ringBuffer(ringBuffer *rb, unsigned char *pp, int sz)
リングバッファにデータを格納する.
Definition: tools.c:3342

References CHAR_CR, CHAR_LF, JBXL_ARGS_ERROR, JBXL_ERROR, JBXL_NORMAL, JBXL_TOOLS_BUF_ERROR, len, and put_ringBuffer().

Referenced by fgets_mstream(), ssl_recv_mstream(), ssl_recv_mstream_Buffer(), ssl_tcp_recv_mstream(), ssl_tcp_recv_mstream_Buffer(), tcp_recv_mstream(), and tcp_recv_mstream_Buffer().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ put_ringBuffer()

int put_ringBuffer ( ringBuffer rb,
unsigned char *  pp,
int  sz 
)

int put_ringBuffer(ringBuffer* rb, unsigned char* pp, int sz)

リングバッファ rb へデータを szバイト格納する.

Parameters
[in]rbリングバッファへのポインタ
[out]rbstate JBXL_NORMAL: バッファは正常状態.JBXL_ERROR: バッファは異常な状態にある.
pp格納するデータへのポインタ.
sz格納するデータのサイズ(Byte)
Return values
0以上書き込んだバイト数.
JBXL_ARGS_ERROR引数にNULLのデータがある.
JBXL_TOOLS_BUF_ERRORバッファ(データ格納)部の領域がない.
JBXL_TOOLS_BUFSZ_ERRORバッファ(データ格納)部の大きさがたりない.データはputされなかった.

Definition at line 3342 of file tools.c.

3343 {
3344  if (rb==NULL) return JBXL_ARGS_ERROR;
3345  rb->state = JBXL_NORMAL;
3346 
3347  if (pp==NULL) return JBXL_ARGS_ERROR;
3348  if (rb->buf==NULL) return JBXL_TOOLS_BUF_ERROR;
3349  if (rb->datasz+sz>rb->bufsz) {
3350  rb->state = JBXL_ERROR;
3351  return JBXL_TOOLS_BUFSZ_ERROR;
3352  }
3353 
3354  if (rb->epoint+sz<=rb->bufsz) {
3355  memcpy(&(rb->buf[rb->epoint]), pp, sz);
3356  rb->epoint = rb->epoint + sz;
3357  if (rb->epoint==rb->bufsz) rb->epoint = 0;
3358  }
3359  else {
3360  memcpy(&(rb->buf[rb->epoint]), pp, rb->bufsz-rb->epoint);
3361  memcpy(rb->buf, &(pp[rb->bufsz-rb->epoint]), sz-(rb->bufsz-rb->epoint));
3362  rb->epoint = rb->epoint + sz - rb->bufsz;
3363  }
3364 
3365  rb->datasz += sz;
3366  return sz;
3367 }
#define JBXL_TOOLS_BUFSZ_ERROR
バッファ(データ格納)部の大きさが足りない
Definition: jbxl_state.h:57
int epoint
バッファデータの終点+1 (データの追加点)
Definition: tools.h:159

References ringBuffer::buf, ringBuffer::bufsz, ringBuffer::datasz, ringBuffer::epoint, JBXL_ARGS_ERROR, JBXL_ERROR, JBXL_NORMAL, JBXL_TOOLS_BUF_ERROR, JBXL_TOOLS_BUFSZ_ERROR, and ringBuffer::state.

Referenced by put_mstream().

Here is the caller graph for this function:

◆ randbit()

unsigned char* randbit ( int  n)

unsigned char* randbit(int n)

ランダムに n bitのバイナリを生成する. 返されたデータは free()する必要がある.

Parameters
n出力する bit数.
Returns
ランダムに生成された n bitのデータ.要 free

Definition at line 1804 of file tools.c.

1805 {
1806  int i, sz;
1807  unsigned char* bin;
1808 
1809  sz = (n+7)/8;
1810  bin = (unsigned char*)malloc(sz);
1811  if (bin==NULL) return NULL;
1812 
1813  memset(bin, 0, sz);
1814  for (i=0; i<n; i++) setBit(bin, i, rand()%2);
1815 
1816  return bin;
1817 }

References setBit.

◆ randstr()

char* randstr ( int  n)

char* randstr(int n)

ランダムに A-Za-z0-9 までの文字を n文字生成する. 返されたデータは free()する必要がある.

Parameters
n出力する文字数.
Returns
ランダムに生成された n文字の文字列.要 free

Definition at line 1777 of file tools.c.

1778 {
1779  char base[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
1780  char* pass;
1781  int i, sz;
1782 
1783  if (n<=0) return NULL;
1784  pass = (char*)malloc(n+1);
1785  if (pass==NULL) return pass;
1786 
1787  sz = (int)strlen(base);
1788  for (i=0; i<n; i++) pass[i] = base[rand()%sz];
1789  pass[n] = '\0';
1790 
1791  return pass;
1792 }

Referenced by command_USERID(), and temp_filename().

Here is the caller graph for this function:

◆ read_file()

unsigned char* read_file ( const char *  fname,
long unsigned int *  size 
)

unsigned char* read_file(const char* fname, long unsigned int* size)

ファイルを読み込んで,データへのポインタを返す.

Parameters
fnameファイル名
size読み込んだデータのサイズを返す.
Returns
読み込んだデータへのポインタ.

Definition at line 2460 of file tools.c.

2461 {
2462  size_t rs;
2463  UNUSED(rs);
2464 
2465  if (size==NULL) return NULL;
2466 
2467  *size = file_size(fname);
2468  if (*size<=0) return NULL;
2469 
2470  unsigned char* buf = (unsigned char*)malloc(*size);
2471  if (buf==NULL) return NULL;
2472  memset(buf, 0, *size);
2473 
2474  FILE* fp = fopen(fname, "rb");
2475  if (fp==NULL) {
2476  free(buf);
2477  return NULL;
2478  }
2479 
2480  rs = fread(buf, *size, 1, fp);
2481  fclose(fp);
2482 
2483  return buf;
2484 }

References buf, file_size(), and UNUSED.

Referenced by read_tiff_file().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ref_ringBuffer()

unsigned char* ref_ringBuffer ( ringBuffer rb,
int  pos 
)

unsigned char* ref_ringBuffer(ringBuffer* rb, int pos)

リングバッファ rb の spoint + pos の位置にあるデータへの参照.

Parameters
rbリングバッファへのポインタ
pos参照するデータの spoint からの位置.
Return values
参照データへのポインタ.

Definition at line 3455 of file tools.c.

3456 {
3457  unsigned char* pp;
3458 
3459  if (rb==NULL) return NULL;
3460  if (rb->buf==NULL) return NULL;
3461  if (pos>rb->datasz) return NULL;
3462 
3463  int sz = rb->spoint + pos;
3464  pp = rb->buf + sz;
3465  if (sz >= rb->bufsz) pp -= rb->bufsz;
3466 
3467  return pp;
3468 }

References ringBuffer::buf, ringBuffer::bufsz, ringBuffer::datasz, and ringBuffer::spoint.

◆ replace_char()

void replace_char ( unsigned char *  buf,
int  len,
unsigned char  frm,
unsigned char  toc 
)

void replace_char(unsigned char* buf, int len, unsigned char frm, unsigned char toc)

buf中の frm (char) を tosで置き換える.

Parameters
buf操作対象のデータ.バイナリも可.
lenbufの領域の大きさ(長さ)'\0'を含む.<= 0 の場合は buf を文字列として扱う.
frm変換するバイトデータ
tos変換後の倍とデータ

Definition at line 1252 of file tools.c.

1253 {
1254  if (buf==NULL) return;
1255  if (len<=0) len = (int)strlen((char*)buf) + 1;
1256 
1257  int i;
1258  for (i=0; i<len; i++) {
1259  if (buf[i]==frm) buf[i] = toc;
1260  }
1261 
1262  return;
1263 }

References buf, and len.

◆ replace_str()

char* replace_str ( char *  buf,
int  len,
const char *  frm,
const char *  tos 
)

char* replace_str(char* buf, int len, const char* frm, const char* tos)

buf中の文字列 frmを tosで置き換える.

bufには十分な領域がなければならない.frmは bufとメモリ領域が重なってはいけない.
失敗した場合は NULLを返し,bufの内容は変化しない.

Parameters
[in]buf操作対象の文字列
[out]buf変換された文字列
lenbuf中の変換対象のbufの領域の大きさ(長さ)
frm変換する文字列
tos変換後の文字列
Returns
buf へのポインタ.失敗した場合は NULL.freeしてはいけない.

Definition at line 1282 of file tools.c.

1283 {
1284  char* wrk = NULL;
1285  int i, j, k, slen, flen, tlen;
1286 
1287  if (buf==NULL || frm==NULL || tos==NULL) return NULL;
1288  if (len<=0) len = (int)strlen(buf) + 1;
1289 
1290  wrk = (char*)malloc(len);
1291  if (wrk==NULL) return NULL;
1292  memset(wrk, 0, len);
1293 
1294  slen = (int)strlen(buf);
1295  flen = (int)strlen(frm);
1296  tlen = (int)strlen(tos);
1297 
1298  i = j = 0;
1299  while (i<slen && j<len) {
1300  if (!strncmp((const char*)(buf+i), frm, flen)){
1301  for (k=0; k<tlen; k++) {
1302  wrk[j+k] = tos[k];
1303  }
1304  i += flen;
1305  j += tlen;
1306  }
1307  else {
1308  wrk[j++] = buf[i++];
1309  }
1310  }
1311 
1312  //
1313  if (j>=len) {
1314  free(wrk);
1315  return NULL;
1316  }
1317 
1318  wrk[j] = '\0';
1319  for (k=0; k<=j; k++) buf[k] = wrk[k];
1320  free(wrk);
1321 
1322  return buf;
1323 }

References buf, and len.

Referenced by bvh_get_seq_data().

Here is the caller graph for this function:

◆ reverse_str()

void reverse_str ( uByte p,
int  s 
)

void reverse_str(uByte* p, int s)

バイト列を逆順にする.

Parameters
[in,out]pバイトデータへのポインタ.
sバイトデータの長さ.

Definition at line 1952 of file tools.c.

1953 {
1954  int i;
1955  uByte c;
1956 
1957  if (s<=0) s = (int)strlen((const char*)p);
1958 
1959  for (i=0; i<s/2; i++) {
1960  c = p[s-1-i];
1961  p[s-1-i] = p[i];
1962  p[i] = c;
1963  }
1964 }

Referenced by double_from_big_endian(), double_from_little_endian(), float_from_big_endian(), float_from_little_endian(), int_from_big_endian(), int_from_little_endian(), short_from_big_endian(), short_from_little_endian(), swap_byte(), uint_from_big_endian(), uint_from_little_endian(), ushort_from_big_endian(), and ushort_from_little_endian().

Here is the caller graph for this function:

◆ seek_ringBuffer()

int seek_ringBuffer ( ringBuffer rb,
int  sz 
)

int seek_ringBuffer(ringBuffer* rb, int sz)

リングバッファ rb の読み取り開始ポインタ spoint を sz 移動させる.

Parameters
rbリングバッファへのポインタ
sz開始ポインタを移動させる量.負数(バック)も可.
Returns
TRUE : 移動に成功.
FALSE : 移動に失敗.
Bug:
バッファ長を超える移動はできない.移動させた先にデータが存在しているかは保障されない.

Definition at line 3424 of file tools.c.

3425 {
3426  if (rb==NULL) return FALSE;
3427  if (rb->buf==NULL) return FALSE;
3428  if (sz>rb->datasz) return FALSE;
3429 
3430  if (rb->spoint+sz>=rb->bufsz) {
3431  rb->spoint = rb->spoint + sz - rb->bufsz;
3432  }
3433  else if (rb->spoint+sz<0) {
3434  rb->spoint = rb->bufsz + rb->spoint + sz;
3435  }
3436  else {
3437  rb->spoint = rb->spoint + sz;
3438  }
3439 
3440  rb->datasz -= sz;
3441  return TRUE;
3442 }

References ringBuffer::buf, ringBuffer::bufsz, ringBuffer::datasz, FALSE, ringBuffer::spoint, and TRUE.

◆ set_sigsegv_handler()

void set_sigsegv_handler ( void(*)(int)  handler)

void set_sigsegv_handler(void (*handler)(int))

セグメンテーションエラー時のハンドラを設定.
引数に NULLを指定した場合は,ハンドラ関数として trap_segmentation_falt() を使用.

Parameters
(*handler)()セグメンテーションエラー時に呼び出される関数へのポインタ
See also
trap_segmentation_falt()

Definition at line 3829 of file tools.c.

3830 {
3831  struct sigaction sa;
3832 
3833  memset(&sa, 0, sizeof(sa));
3834  if (handler!=NULL) sa.sa_handler = handler;
3835  else sa.sa_handler = trap_segmentation_falt;
3836 
3837  sa.sa_flags = 0;
3838  sigemptyset(&sa.sa_mask);
3839  sigaction(SIGSEGV, &sa, NULL);
3840 }
void trap_segmentation_falt(int signal)
セグメンテーションエラー時にデフォルトで呼び出される関数.
Definition: tools.c:3850

References trap_segmentation_falt().

Here is the call graph for this function:

◆ set_sigterm_child()

void set_sigterm_child ( void(*)(int)  handler)

void set_sigterm_child(void (*handler)(int))

child プロセス終了時の処理を設定.

Parameters
(*handler)()チャイルドプロセス終了時に呼び出される関数へのポインタ@ NULL の場合は void sigterm_child(int signal) が設定される.
Attention
シグナル関係の関数は Windowsでは使用できない

Definition at line 3763 of file tools.c.

3764 {
3765  struct sigaction sa;
3766 
3767  memset(&sa, 0, sizeof(sa));
3768  if (handler!=NULL) sa.sa_handler = handler;
3769  else sa.sa_handler = sigterm_child;
3770 
3771  sa.sa_flags = SA_NOCLDSTOP | SA_RESTART;
3772  sigemptyset(&sa.sa_mask);
3773  sigaddset(&sa.sa_mask, SIGINT); // SIGCHLD 処理中は SIGINT をブロック
3774  sigaddset(&sa.sa_mask, SIGHUP); // SIGCHLD 処理中は SIGHUP をブロック
3775  sigaddset(&sa.sa_mask, SIGTERM); // SIGCHLD 処理中は SIGTERM をブロック
3776  sigaction(SIGCHLD, &sa, NULL);
3777 }
void sigterm_child(int signal)
child プロセス終了時の処理
Definition: tools.c:3787

References sigterm_child().

Here is the call graph for this function:

◆ short_from_big_endian()

short short_from_big_endian ( void *  ptr)

short short_from_big_endian(void* ptr)

Big Endian形式で格納されている short int型の値を取り出す.

Parameters
ptr変数が格納されているメモリへのポインタ
Returns
取り出した short int型の値

Definition at line 336 of file tools.c.

337 {
338  short ret = *((short*)ptr);
339 
341  if (HostEndian==LITTLE_ENDIAN) reverse_str((uByte*)(&ret), 2);
342  return ret;
343 }

References check_endian(), HostEndian, LITTLE_ENDIAN, reverse_str(), and UNKNOWN_ENDIAN.

Here is the call graph for this function:

◆ short_from_little_endian()

short short_from_little_endian ( void *  ptr)

short short_from_little_endian(void* ptr)

Little Endian形式で格納されている short int型の値を取り出す.

Parameters
ptr変数が格納されているメモリへのポインタ
Returns
取り出した short int型の値

Definition at line 228 of file tools.c.

229 {
230  short ret = *((short*)ptr);
231 
233  if (HostEndian==BIG_ENDIAN) reverse_str((uByte*)(&ret), 2);
234  return ret;
235 }

References BIG_ENDIAN, check_endian(), HostEndian, reverse_str(), and UNKNOWN_ENDIAN.

Here is the call graph for this function:

◆ sigterm_child()

void sigterm_child ( int  signal)

void sigterm_child(int signal)

child プロセス終了時の処理

Parameters
signalハンドラのシグナル番号.システムによって設定される.

Definition at line 3787 of file tools.c.

3788 {
3789  UNUSED(signal);
3790 
3791  pid_t pid = 0;
3792  int ret;
3793 
3794  //DEBUG_MODE PRINT_MESG("%d is waiting for children. signal = %d\n", getpid(), signal);
3795  //signal = 0; // dummy for warning of compiler
3796 
3797  do { // チャイルドプロセスの終了を待つ
3798  pid = waitpid(-1, &ret, WNOHANG);
3799  } while(pid>0);
3800 }

References UNUSED.

Referenced by set_sigterm_child().

Here is the caller graph for this function:

◆ sjis2euc()

void sjis2euc ( unsigned char *  c1,
unsigned char *  c2 
)

void sjis2euc(unsigned char *c1, unsigned char *c2)

漢字コード変換.SJIS → EUC

Parameters
[in,out]c1変換する文字の第一バイト.内容が書き換えられる.
[in,out]c2変換する文字の第二バイト.内容が書き換えられる.

Definition at line 2717 of file tools.c.

2718 {
2719  if (*c2<0x9f) {
2720  if (*c1 < 0xa0) {
2721  *c1 -= 0x81;
2722  *c1 *= 2;
2723  *c1 += 0xa1;
2724  }
2725 
2726  else {
2727  *c1 -= 0xe0;
2728  *c1 *= 2;
2729  *c1 += 0xdf;
2730  }
2731  if (*c2>0x7f) (*c2)--;
2732  *c2 += 0x61;
2733  }
2734  else {
2735  if (*c1<0xa0) {
2736  *c1 -= 0x81;
2737  *c1 *= 2;
2738  *c1 += 0xa2;
2739  }
2740  else {
2741  *c1 -= 0xe0;
2742  *c1 *= 2;
2743  *c1 += 0xe0;
2744  }
2745  *c2 += 2;
2746  }
2747 }

Referenced by kanji_convert_sjis2euc().

Here is the caller graph for this function:

◆ skip_char()

char* skip_char ( char *  pp,
char  cc 
)

char* skip_char(char* pp, char cc)

文字列 pp の中で,次の cc までポインタをスキップさせる.
ただし," ", ' ' 内に該当文字があった場合,それらは無視される.

Parameters
pp文字列の先頭ポインタ
ccスキップする文字を格納した文字列.
Returns
check[]の中で最初に見つかった文字へのポインタ.

Definition at line 985 of file tools.c.

986 {
987  int sqf = 0, dqf = 0;
988 
989  while (*pp!='\0') {
990  while (*pp=='\\') pp += 2;
991  //
992  if (*pp!='\0') {
993  if (!sqf && *pp=='\"') dqf = 1 - dqf;
994  else if (!dqf && *pp=='\'') sqf = 1 - sqf;
995  else if (!sqf && !dqf && *pp==cc) return pp;
996  pp++;
997  }
998  }
999 
1000  return pp;
1001 }

◆ skip_char_pair()

char* skip_char_pair ( char *  pp,
char  pair,
char  end 
)

char* skip_char_pair(char* pp, char pair, char end)

pair から始まって end で閉じるまで,ポインタをスキップさせる.ただし " " と ' ' 内は完全スキップ
pair と end は対になっている必要がある.
pp は pair の位置を指しているのが望ましい.指していなくても動くけど....
ペアの end がない場合は '\0' へのポインタを返す.

Parameters
pp操作対象の文字列
pairペアとなる最初の文字
endペアとなる最後の文字
Returns
ペアとなった最後の文字へのポインタ
pt = skip_char_pair(pp, '<', '>');
char * skip_char_pair(char *pp, char pair, char end)
pair と end で閉じるまでポインタをスキップさせる.ただし クォーテーション内は完全スキップ
Definition: tools.c:1022

Definition at line 1022 of file tools.c.

1023 {
1024  int cnt = 0, sqf = 0, dqf = 0;
1025 
1026  if (*pp==pair) {
1027  cnt = 1;
1028  pp++;
1029  }
1030 
1031  while (*pp!='\0') {
1032  while (*pp=='\\') pp += 2;
1033  //
1034  if (*pp!='\0') {
1035  if (!sqf && *pp=='\"') dqf = 1 - dqf;
1036  else if (!dqf && *pp=='\'') sqf = 1 - sqf;
1037 
1038  else if (!sqf && !dqf) {
1039  if (*pp==end) cnt--;
1040  else if (*pp==pair) cnt++;
1041  if (cnt==0) return pp;
1042  }
1043  pp++;
1044  }
1045  }
1046 
1047  return pp;
1048 }

Referenced by json_array_parse(), and json_parse_prop().

Here is the caller graph for this function:

◆ skip_chars()

char* skip_chars ( char *  pp,
const char *  check 
)

char* skip_chars(char* pp, const char* check)

ppの指す文字列中で,check[]に格納されたいずれかの文字までポインタをスキップさせる.
ただし," ", ' ' 内に該当文字があった場合,それらは無視される.

Parameters
pp文字列の先頭ポインタ
checkスキップする文字を格納した文字列.
Returns
check[]の中で最初に見つかった文字へのポインタ.

Definition at line 948 of file tools.c.

949 {
950  int n, sqf = 0, dqf = 0;
951 
952  n = (int)strlen(check);
953 
954  while (*pp!='\0') {
955  while (*pp=='\\') pp += 2;
956  //
957  if (*pp!='\0') {
958  if (!sqf && *pp=='\"') dqf = 1 - dqf;
959  else if (!dqf && *pp=='\'') sqf = 1 - sqf;
960 
961  else if (!sqf && !dqf) {
962  int i;
963  for (i=0; i<n; i++) {
964  if (*pp==check[i]) return pp;
965  }
966  }
967  pp++;
968  }
969  }
970 
971  return NULL;
972 }

Referenced by json_array_parse(), xml_parse_comment_node(), xml_parse_data_node(), xml_parse_end_node(), xml_parse_processing_node(), and xml_parse_start_node().

Here is the caller graph for this function:

◆ skip_string_end()

char* skip_string_end ( char *  pp)

char* skip_string_end(char* pp)

文字列の最後までポインタをスキップする.
ppの指す文字列 "〜" または '〜' の最後の クォーテーションへのポインタ

Parameters
pp文字列の先頭の クォーテーションへのポインタ
Returns
文字列の最後の クォーテーションへのポインタ

Definition at line 1060 of file tools.c.

1061 {
1062  char ch = *pp;
1063 
1064  if (*pp=='\"' || *pp=='\'') {
1065  pp++;
1066  //
1067  while (*pp!='\0') {
1068  while (*pp=='\\') pp += 2;
1069  //
1070  if (*pp!='\0') {
1071  if (*pp==ch) return pp;
1072  }
1073  pp++;
1074  }
1075  }
1076  return pp;
1077 }

Referenced by json_parse_prop().

Here is the caller graph for this function:

◆ strncaservscmp()

int strncaservscmp ( const char *  s1,
const char *  s2,
int  n 
)

int strncaservscmp(const char* s1, const char* s2, int n)

文字列 s1と s2を後ろから n文字比較する.

Return values
0一致する
1一致しない
Attention
strncmp()の戻り値の定義とは若干異なるので注意すること.

Definition at line 703 of file tools.c.

704 {
705  int j1, j2;
706 
707  if (s1==NULL || s2==NULL) return 1;
708 
709  j1 = (int)strlen(s1) - 1;
710  j2 = (int)strlen(s2) - 1;
711 
712  while (n>0 && j1>=0 && j2>=0) {
713  if (toupper(s1[j1--]) != toupper(s2[j2--])) return 1;
714  n--;
715  }
716 
717  if (n==0) return 0;
718  else return 1;
719 }

Referenced by ex_strncaservscmp().

Here is the caller graph for this function:

◆ strnrvscmp()

int strnrvscmp ( const char *  s1,
const char *  s2,
int  n 
)

int strnrvscmp(const char* s1, const char* s2, int n)

文字列 s1と s2を後ろから n文字比較する.

Return values
0一致する
1一致しない
Attention
strncmp()の戻り値の定義とは若干異なるので注意すること.

Definition at line 674 of file tools.c.

675 {
676  int j1, j2;
677 
678  if (s1==NULL || s2==NULL) return 1;
679 
680  j1 = (int)strlen(s1) - 1;
681  j2 = (int)strlen(s2) - 1;
682 
683  while (n>0 && j1>=0 && j2>=0) {
684  if (s1[j1--] != s2[j2--]) return 1;
685  n--;
686  }
687 
688  if (n==0) return 0;
689  else return 1;
690 }

Referenced by ex_strnrvscmp(), is_host_in_list(), and recv_mesg_until_end().

Here is the caller graph for this function:

◆ strstrcase()

char* strstrcase ( const char *  buf,
const char *  nd 
)

char* strstrcase(const char* buf, const char* nd)

文字列 bufの中に部分文字列 ndがあるかどうかをチェックする.大文字小文字を区別しない.

大文字小文字を区別しない点を除けば,strstr() と同じ.
つまり strcasestr() と同じ.標準で strcasestr()が存在しない場合に使用.

Parameters
buf検索対象の文字列
nd検索する部分文字列
Returns
部分文字列の開始を指すポインタ.部分文字列が見つからない場合は NULL
See also
strstr(), strcasestr()

Definition at line 736 of file tools.c.

737 {
738  char* pp;
739  char* pb;
740  char* pn;
741 
742  if (buf==NULL || nd==NULL) return NULL;
743 
744  pb = (char*)malloc(strlen(buf)+1);
745  if (pb==NULL) return NULL;
746  memcpy(pb, buf, (int)strlen(buf)+1);
747 
748  pn = (char*)malloc(strlen(nd)+1);
749  if (pn==NULL) {
750  free(pb);
751  return NULL;
752  }
753  memcpy(pn, nd, (int)strlen(nd)+1);
754 
755  upper_string(pb);
756  upper_string(pn);
757 
758  pp = strstr(pb, pn);
759  if (pp!=NULL) {
760  pp = (pp - pb) + (char*)buf;
761  }
762  free(pb);
763  free(pn);
764 
765  return pp;
766 }
void upper_string(char *str)
Definition: tools.c:2757

References buf, and upper_string().

Referenced by get_mime_enckind(), get_mime_filename(), get_sip_via_address(), insert_sip_record_route(), replace_sip_contact(), search_protocol_header_partvalue(), strstrcase_back_tList(), and strstrcase_tList().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ swap_byte()

void swap_byte ( void *  p,
int  s,
int  c 
)

void swap_byte(void* p, int s, int c)

上位バイトと下位バイトを逆順にする.

pが指す長さ sのデータを cバイトづつ逆順にする.

Parameters
[in,out]pデータへのポインタ.
sデータの長さ.バイト単位.
c逆順にするデータの長さ.バイト単位.

Definition at line 1854 of file tools.c.

1855 {
1856  int i;
1857  uByte* u = (uByte*)p;
1858  for (i=0; i<s; i+=c) reverse_str(&u[i], c);
1859 }

References reverse_str().

Here is the call graph for this function:

◆ swapd()

long long int swapd ( long unsigned long int  p)

◆ swapl()

int swapl ( unsigned int  p)

int swapl(unsigned int p)

int型 32bit pを8bitづつ逆順にする

ntohl(), htonl()の代替関数.Windows用.

Parameters
p入れ替える値
Returns
処理後の値

Definition at line 1896 of file tools.c.

1897 {
1898  int r;
1899  uByte* t;
1900  uByte* f;
1901 
1902  t = (uByte*)&r;
1903  f = (uByte*)&p;
1904  t[0] = f[3];
1905  t[1] = f[2];
1906  t[2] = f[1];
1907  t[3] = f[0];
1908 
1909  return r;
1910 }

Referenced by get_tiff_ifd(), and get_tiff_uint_field().

Here is the caller graph for this function:

◆ swaps()

short swaps ( unsigned short  p)

short swaps(unsigned short p)

short型(16bit)pの上下8bitを入れ替える. ntohs(), htons()の代替関数.Windows用.

Parameters
p入れ替える値
Returns
処理後の値

Definition at line 1872 of file tools.c.

1873 {
1874  short r;
1875  uByte* t;
1876  uByte* f;
1877 
1878  t = (uByte*)&r;
1879  f = (uByte*)&p;
1880  t[0] = f[1];
1881  t[1] = f[0];
1882 
1883  return r;
1884 }

Referenced by get_tiff_ifd(), get_tiff_uint_field(), and read_user_data().

Here is the caller graph for this function:

◆ temp_filename()

char* temp_filename ( const char *  dir,
int  flen 
)

char* temp_filename(const char* dir, int flen)

/dev/urandom を利用して作業用ファイルのランダムなファイル名を得る.

/dev/urandom が読めない場合は randstr() を利用する. 返されたデータは free()する必要がある.

Parameters
dir作業ファイルを作るディレクトリ
flen生成するファイル名の長さ
Returns
作業用ファイル名のフルパス.要 free

Definition at line 2397 of file tools.c.

2398 {
2399  FILE* fp;
2400  int i, dlen=0;
2401  char nostr = '\0';
2402  char* fname;
2403  char* fnbin;
2404  char* fnb64;
2405  size_t rs;
2406  UNUSED(rs);
2407 
2408  if (dir==NULL) dir = &nostr;
2409  dlen = (int)strlen(dir);
2410  if (flen<=0) flen = 15;
2411 
2412  fname = (char*)malloc(dlen+flen+1);
2413  if (fname==NULL) return NULL;
2414  memset(fname, 0, dlen+flen+1);
2415 
2416  fnbin = (char*)malloc(flen);
2417  if (fnbin==NULL) {
2418  free(fname);
2419  return NULL;
2420  }
2421  memset(fnbin, 0, flen);
2422 
2423  fnb64 = NULL;
2424  fp = fopen("/dev/urandom", "rb");
2425 
2426  do {
2427  if (fp!=NULL) {
2428  rs = fread(fnbin, flen, 1, fp);
2429  fnb64 = (char*)encode_base64((unsigned char*)fnbin, flen);
2430  if (fnb64!=NULL) fnb64[flen] = '\0';
2431  }
2432  if (fnb64==NULL) fnb64 = randstr(flen);
2433 
2434  for (i=0; i<flen; i++) {
2435  if (fnb64[i]=='/') fnb64[i] = 'x';
2436  if (fnb64[i]=='+') fnb64[i] = 'X';
2437  }
2438 
2439  memset (fname, 0, dlen+flen+1);
2440  strncpy(fname, dir, dlen);
2441  strncat(fname, fnb64, flen);
2442  free(fnb64);
2443  } while(file_exist(fname));
2444 
2445  if (fp!=NULL) fclose(fp);
2446  free(fnbin);
2447  return fname;
2448 }
char * randstr(int n)
ランダムに A-Za-z0-9 までの文字を n文字生成する.
Definition: tools.c:1777

References encode_base64(), file_exist(), randstr(), and UNUSED.

Referenced by gz_decode_file_replace(), and save_http_xml().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ trap_segmentation_falt()

void trap_segmentation_falt ( int  signal)

void trap_segmentation_falt(int signal)

セグメンテーションエラー時にデフォルトで呼び出される関数.

Parameters
signalハンドラのシグナル番号.システムによって設定される.

Definition at line 3850 of file tools.c.

3851 {
3852  PRINT_MESG("****************************************************************\n");
3853  PRINT_MESG("* Segmentation Falt in [%d] !!!!!\n", getpid());
3854  PRINT_MESG("****************************************************************\n");
3855 
3856  exit(signal);
3857 }

References PRINT_MESG.

Referenced by set_sigsegv_handler().

Here is the caller graph for this function:

◆ uint_from_big_endian()

unsigned int uint_from_big_endian ( void *  ptr)

unsigned int uint_from_big_endian(void* ptr)

Big Endian形式で格納されている unsigned int型の値を取り出す.

Parameters
ptr変数が格納されているメモリへのポインタ
Returns
取り出した unsigned int型の値

Definition at line 318 of file tools.c.

319 {
320  int ret = *((unsigned int*)ptr);
321 
323  if (HostEndian==LITTLE_ENDIAN) reverse_str((uByte*)(&ret), 4);
324  return ret;
325 }

References check_endian(), HostEndian, LITTLE_ENDIAN, reverse_str(), and UNKNOWN_ENDIAN.

Here is the call graph for this function:

◆ uint_from_little_endian()

unsigned int uint_from_little_endian ( void *  ptr)

unsigned int uint_from_little_endian(void* ptr)

Little Endian形式で格納されている unsigned int型の値を取り出す.

Parameters
ptr変数が格納されているメモリへのポインタ
Returns
取り出した unsigned int型の値

Definition at line 210 of file tools.c.

211 {
212  unsigned int ret = *((unsigned int*)ptr);
213 
215  if (HostEndian==BIG_ENDIAN) reverse_str((uByte*)(&ret), 4);
216  return ret;
217 }

References BIG_ENDIAN, check_endian(), HostEndian, reverse_str(), and UNKNOWN_ENDIAN.

Here is the call graph for this function:

◆ ulltostr()

char* ulltostr ( long unsigned long int  n)

◆ ulltostr_ts()

char* ulltostr_ts ( long unsigned long int  n)

◆ ultostr()

char* ultostr ( long unsigned int  n)

◆ ultostr_ts()

char* ultostr_ts ( long unsigned int  n)

◆ upper_string()

void upper_string ( char *  str)

void upper_string(char* str)

str中の小文字を大文字に変換する

Parameters
[in,out]str変換する文字列へのポインタ.内容が書き換えられる.

Definition at line 2757 of file tools.c.

2758 {
2759  int i;
2760  for (i=0; i<(int)strlen((const char*)str); i++) {
2761  if (str[i]>='a' && str[i]<='z') str[i] += 'A' - 'a';
2762  }
2763 }

Referenced by strstrcase().

Here is the caller graph for this function:

◆ ushort_from_big_endian()

unsigned short ushort_from_big_endian ( void *  ptr)

unsigned short ushort_from_big_endian(void* ptr)

Big Endian形式で格納されている unsigned short int型の値を取り出す.

Parameters
ptr変数が格納されているメモリへのポインタ
Returns
取り出した unsigned short int型の値

Definition at line 354 of file tools.c.

355 {
356  unsigned short ret = *((unsigned short*)ptr);
357 
359  if (HostEndian==LITTLE_ENDIAN) reverse_str((uByte*)(&ret), 2);
360  return ret;
361 }

References check_endian(), HostEndian, LITTLE_ENDIAN, reverse_str(), and UNKNOWN_ENDIAN.

Here is the call graph for this function:

◆ ushort_from_little_endian()

unsigned short ushort_from_little_endian ( void *  ptr)

unsigned short ushort_from_little_endian(void* ptr)

Little Endian形式で格納されている unsigned short int型の値を取り出す.

Parameters
ptr変数が格納されているメモリへのポインタ
Returns
取り出した unsigned short int型の値

Definition at line 246 of file tools.c.

247 {
248  unsigned short ret = *((unsigned short*)ptr);
249 
251  if (HostEndian==BIG_ENDIAN) reverse_str((uByte*)(&ret), 2);
252  return ret;
253 }

References BIG_ENDIAN, check_endian(), HostEndian, reverse_str(), and UNKNOWN_ENDIAN.

Here is the call graph for this function:

◆ uuid2guid()

unsigned char* uuid2guid ( unsigned char *  p)

unsigned char* uuid2guid(unsigned char* p)

バイナリの UUID を テキストのGUIDに変換する.要 free()

Parameters
pバイナリの UUID. 128bit
Returns
テキストの GUID. 要 free

Definition at line 3629 of file tools.c.

3630 {
3631  unsigned char* guid;
3632 
3633  if (p==NULL) return NULL;
3634 
3635  guid = (unsigned char*)malloc(LGUID); // 40 = 32+4+1(\0) + α
3636  if (guid==NULL) return NULL;
3637  memset(guid, 0, LGUID);
3638 
3639  snprintf((char*)guid, 37, "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
3640  p[0],p[1],p[2],p[3],p[4],p[5],p[6],p[7],p[8],p[9],p[10],p[11],p[12],p[13],p[14],p[15]);
3641 
3642  return guid;
3643 }
#define LGUID
16*2 + 4(-) + 1('\0') = 37 以上の 4の倍数
Definition: common.h:159

References LGUID.

Referenced by llsd_bin_main_parse().

Here is the caller graph for this function:

◆ write_file()

long unsigned int write_file ( const char *  fname,
unsigned char *  buf,
long unsigned int  size 
)

unsigned long int write_file(const char* fname, unsigned char* buf, long unsigned int size)

ファイルにデータを書き込む

Parameters
fnameファイル名.
buf書き込むデータへのポインタ.
size書き込むデータのサイズ.
Returns
実際に書き込んだデータサイズ

Definition at line 2497 of file tools.c.

2498 {
2499  if (size==0) return 0;
2500 
2501  FILE* fp = fopen(fname, "wb");
2502  if (fp==NULL) return 0;
2503 
2504  size = (long unsigned int)fwrite(buf, size, 1, fp);
2505  fclose(fp);
2506 
2507  return size;
2508 }

References buf.

Referenced by extract_tTar().

Here is the caller graph for this function:

Variable Documentation

◆ DebugMode

int DebugMode
extern

Definition at line 17 of file tools.c.

◆ FP_ErrFile

FILE* FP_ErrFile
extern

Definition at line 3894 of file tools.c.

Referenced by close_errfile(), open_errfile(), and print_errfile().

◆ FP_LogFile

FILE* FP_LogFile
extern

Definition at line 3893 of file tools.c.

Referenced by close_logfile(), open_errfile(), open_logfile(), and print_logfile().

◆ HostEndian

◆ KanjiCode

int KanjiCode
extern

処理用漢字コード.CODE_US, CODE_SJIS, CODE_EDUがある.デフォルトは CODE_US.

Definition at line 20 of file tools.c.

Referenced by kanji_convert(), and kanji_convert_Buffer().

◆ LocalIPNum

unsigned char LocalIPNum[4]
extern

Definition at line 26 of file tools.c.

◆ LocalIPNum6

unsigned char LocalIPNum6[16]
extern

Definition at line 27 of file tools.c.

◆ UnitTestMode

int UnitTestMode
extern

Definition at line 18 of file tools.c.

◆ UsedMemoryBase

long unsigned int UsedMemoryBase
extern

Definition at line 23 of file tools.c.

Referenced by memory_check(), and memory_check_start().