root/include/cmem.h

/* [<][>][^][v][top][bottom][index][help] */

INCLUDED FROM


   1 #ifndef YACASL2_CMEM_H_INCLUDED
   2 #define YACASL2_CMEM_H_INCLUDED
   3 
   4 #include <stdio.h>
   5 #include <stdlib.h>
   6 #include <string.h>
   7 #include <assert.h>
   8 #include <stdbool.h>
   9 
  10 /**
  11  * @brief 配列のサイズを返すマクロ
  12  */
  13 #ifndef ARRAYSIZE
  14 #define ARRAYSIZE(array) (sizeof(array)/sizeof(array[0]))
  15 #endif
  16 
  17 /**
  18  * @brief メモリを解放するマクロ
  19  */
  20 #ifndef FREE
  21 #define FREE(ptr) {free(ptr); ptr = NULL;}
  22 #endif
  23 
  24 /**
  25  * @brief mallocを実行し、0で初期化する
  26  *
  27  * メモリを確保できない場合はエラーを出力して終了
  28  *
  29  * @param size メモリーのサイズ
  30  * @param tag エラーメッセージなどで表示されるタグ
  31  */
  32 void *malloc_chk(size_t size, const char *tag);
  33 
  34 /**
  35  * @brief 領域の数とサイズを指定してメモリーを確保するcallocを実行する
  36  *
  37  * メモリを確保できない場合はエラーを出力して終了
  38  *
  39  * @param nmemb 領域の数
  40  * @param size 領域1個あたりのメモリーサイズ
  41  * @param tag エラーメッセージなどで表示されるタグ
  42  */
  43 void *calloc_chk(size_t nmemb, size_t size, const char *tag);
  44 
  45 /**
  46  * @brief malloc_chkを実行してメモリを確保し、コピーした文字列を返す
  47  *
  48  * @return コピーした文字列
  49  *
  50  * @param s 文字列
  51  * @param tag エラーメッセージなどで表示されるタグ
  52  */
  53 char *strdup_chk(const char *s, const char *tag);
  54 
  55 /**
  56  * @brief malloc_chkを実行してメモリを確保し、コピーした文字列の指定した長さの部分を返す
  57  *
  58  * @return コピーした文字列
  59  *
  60  * @param s 文字列
  61  * @param len 文字列の長さ
  62  * @param tag エラーメッセージなどで表示されるタグ
  63  */
  64 char *strndup_chk(const char *s, size_t len, const char *tag);
  65 
  66 /**
  67  * @brief 文字列の末尾から、改行と空白とタブを削除する
  68  *
  69  * @param s 文字列
  70  */
  71 void strip_end(char *s);
  72 
  73 /**
  74  * @brief 文字列から「'」以降の文字列をCASL IIのコメントとして削除する。「''」の場合は除く
  75  *
  76  * @param s 文字列
  77  */
  78 void strip_casl2_comment(char *s);
  79 
  80 /**
  81  * @brief 逆にした文字列を返す
  82  *
  83  * @return 逆にしたした文字列
  84  *
  85  * @param s 文字列
  86  */
  87 char *strrev(const char *s);
  88 
  89 #endif

/* [<][>][^][v][top][bottom][index][help] */