common code for do_rumors(). Return 0 on error. */
| 1033 | |
| 1034 | /* common code for do_rumors(). Return 0 on error. */ |
| 1035 | static unsigned long |
| 1036 | read_rumors_file( |
| 1037 | const char *file_ext, |
| 1038 | int *rumor_count, |
| 1039 | long *rumor_size, |
| 1040 | unsigned long old_rumor_offset, |
| 1041 | unsigned padlength) |
| 1042 | { |
| 1043 | char infile[MAXFNAMELEN], xbuf[BUFSZ]; |
| 1044 | char *line; |
| 1045 | unsigned long rumor_offset; |
| 1046 | |
| 1047 | Sprintf(infile, DATA_IN_TEMPLATE, RUMOR_FILE); |
| 1048 | Strcat(infile, file_ext); |
| 1049 | if (!(ifp = fopen(infile, RDTMODE))) { |
| 1050 | perror(infile); |
| 1051 | return 0L; |
| 1052 | } |
| 1053 | set_fgetline_context(infile, TRUE, FALSE); |
| 1054 | |
| 1055 | /* copy the rumors */ |
| 1056 | while ((line = fgetline(ifp)) != 0) { |
| 1057 | (void) padline(line, padlength); /* make shortest lines be longer */ |
| 1058 | |
| 1059 | (*rumor_count)++; |
| 1060 | #if 0 |
| 1061 | /*[if we forced binary output, this would be sufficient]*/ |
| 1062 | *rumor_size += strlen(line); /* includes newline */ |
| 1063 | #endif |
| 1064 | (void) fputs(xcrypt(line, xbuf), tfp); |
| 1065 | free((genericptr_t) line); |
| 1066 | } |
| 1067 | /* record the current position; next rumors section will start here */ |
| 1068 | rumor_offset = (unsigned long) ftell(tfp); |
| 1069 | Fclose(ifp); /* all done with rumors.file_ext */ |
| 1070 | |
| 1071 | /* the calculated value for *_rumor_count assumes that |
| 1072 | a single-byte line terminator is in use; for platforms |
| 1073 | which use two byte CR+LF, we need to override that value |
| 1074 | [it's much simpler to do so unconditionally, rendering |
| 1075 | the loop's accumulation above obsolete] */ |
| 1076 | *rumor_size = (long) (rumor_offset - old_rumor_offset); |
| 1077 | return rumor_offset; |
| 1078 | } |
| 1079 | |
| 1080 | static void |
| 1081 | do_rnd_access_file( |