追加更新モードでファイルを開いた後、ファイルへの各書き込みの前にファイル配置ステートメントを実行する必要がありますか?
FILE *h;
int ch;
if ((h = fopen("data", "a+")) == NULL) exit(1);
if (fseek(h, 0 SEEK_SET)) exit(2);
ch = fgetc(h); /* read very first character */
if (ch == EOF) exit(3);
/* redundant? mandatory? */
fseek(h, 0, SEEK_END); /* call file positioning before output */
/* add 1st character to the end of file on a single line*/
fprintf(h, "%c\n", ch);
C11 標準は次のように述べています。
7.21.5.3/6 ... ファイルへの後続のすべての書き込みは、その時点で最新のファイルの終わりに強制されます ...
と
7.21.5.3/7 ... ファイル配置関数の呼び出しを介在させずに、入力の直後に出力を続けてはならない ...
7.21.5.3/7のshallは7.21.5.3/6の説明より強いと思います。