前面的做的有些修改,解释更加透彻了。
从13层接着说
完成了 模糊匹配后,将所有的模糊相等的都链入链表中。
然后[code]
_getopt_internal_r()
{
. . . . .
542
543 FILE *fp = open_memstream (&buf, &buflen);
544 if (fp != NULL)
545 {
546 fprintf (fp,
547 _("%s: option '%s' is ambiguous; possibilities:" ), /*打开此文件*/
548 argv[0], argv[d->optind]);
549
550 do
551 {
552 fprintf (fp, " '--%s'", ambig_list->p->name); /*将刚才的那些模糊匹配的打印进此“文件中"*/
553 ambig_list = ambig_list->next;
554 } /*
555 while (ambig_list != NULL); /*
556
557 fputc_unlocked ('\n', fp);
558
559 if (__builtin_expect (fclose (fp) != EOF, 1)) /*这是一个expect函数,提前控制分支,博客有分析*/
560 {
561 _IO_flockfile (stderr);
562
}
[/code]这有个open_memstream(&buf, &buflen);的函数。
The open_memstream() opens a stream for writing to a buffer. The buffer is dynamically allocated (as with malloc(3)), and automatically grows as required. After closing the stream, the caller should free(3) this buffer.
When the stream is closed (fclose(3)) or flushed (fflush(3)), the locations pointed to by ptr and sizeloc are updated to contain, respectively, a pointer to the buffer and the current size of the buffer. These values remain valid only as long as the caller performs no further output on the stream. If further output is performed, then the stream must again be flushed before trying to access these variables.
A null byte is maintained at the end of the buffer. This byte is not included in the size value stored at sizeloc.
翻译吧: 这个open_memstream()为写入缓冲区打开一个流。这个缓冲区是动态分配的(用malloc()),随要求动态增长的。当关闭这个流时,调用者应该用free()来释放这个缓冲区。
当这个流被fclose()或者fflush()函数关闭,ptr指向的位置和sizeloc被更新来包含相应的指向buffer的指针和当前的缓冲区的大小。这个值依然是有效的只要调用者没有向这个流输出。如果输出,这个流一定被再次冲刷,然后尝试访问这些变量。
一个 \0 字节放在缓冲区的最后。这个字节不被包含到sizeloc的大小中。
意思是,创建一个文件,写入时就写入内存中。
int fprintf ( FILE * stream, const char * format, ... );
Write formatted output to stream
向特定的流写入以一定格式格式化的数据。
阅读(1365) | 评论(0) | 转发(0) |