アットウィキロゴ

vsftpd_1.2.1_str.c_str_getline

str_getline


source

str.c

line

599 - 630

概要


int str_getline(const struct mystr* p_str, struct mystr* p_line_str,
               unsigned int* p_pos);

  • PURPOSE

  Extract a line of text (delimited by \n or EOF) from a string
* buffer, starting at character position 'p_pos'. The extracted line will
* not contain the '\n' terminator.
'p_pos'という欄で始まって、ストリング*バッファからテキスト行(\のnかEOFによって区切られる)を抜粋してください。 
'抽出された線意志*は'\n'ターミネータを含んでいません。

  • RETURNS:

  0 if no more lines are available, 1 otherwise.
* The extracted text line is stored in 'p_line_str', which is
* emptied if there are no more lines. 'p_pos' is updated to point to the
* first character after the end of the line just extracted.
0 それ以上の線が利用可能でないなら、1 そうでなければ。
*抽出されたテキスト線は'_p線_str'に格納されて、それ以上の線が全くなければ、どれが*であるかは空になりました。 
最初に、行の終わり以降キャラクタがただ抽出した*を示すために'p_pos'をアップデートします。

function


   599 int
   600 str_getline(const struct mystr* p_str, struct mystr* p_line_str,
   601             unsigned int* p_pos)
   602 {
   603   unsigned int start_pos = *p_pos;
   604   unsigned int curr_pos = start_pos;
   605   unsigned int buf_len = str_getlen(p_str);
   606   const char* p_buf = str_getbuf(p_str);
   607   unsigned int out_len;
   608   if (start_pos > buf_len)
   609   {
   610     bug("p_pos out of range in str_getline");
   611   }
   612   str_empty(p_line_str);
   613   if (start_pos == buf_len)
   614   {
   615     return 0;
   616   }
   617   while (curr_pos < buf_len && p_buf[curr_pos] != '\n')
   618   {
   619     curr_pos++;
   620   }
   621   out_len = curr_pos - start_pos;
   622   /* If we ended on a \n - skip it */
   623   if (curr_pos < buf_len && p_buf[curr_pos] == '\n')
   624   {
   625     curr_pos++;
   626   }
   627   private_str_alloc_memchunk(p_line_str, p_buf + start_pos, out_len);
   628   *p_pos = curr_pos;
   629   return 1;
   630 }
最終更新:2009年02月09日 21:22
ツールボックス

下から選んでください:

新しいページを作成する
ヘルプ / FAQ もご覧ください。