3 * Copyright (c) 1992-2001 by Mike Gleason.
13 extern int gMaxLogSize
;
14 char gLogFileName
[256];
16 extern char gOurDirectoryPath
[];
22 OurDirectoryPath(gLogFileName
, sizeof(gLogFileName
), kLogFileName
);
28 LogXfer(const char *const mode
, const char *const url
)
33 return; /* Don't log */
35 fp
= fopen(gLogFileName
, FOPEN_APPEND_TEXT
);
37 (void) fprintf(fp
, " %s %s\n", mode
, url
);
45 LogOpen(const char *const host
)
51 return; /* Don't log */
54 fp
= fopen(gLogFileName
, FOPEN_APPEND_TEXT
);
56 (void) fprintf(fp
, "%s at %s", host
, ctime(&now
));
73 if (gOurDirectoryPath
[0] == '\0')
74 return; /* Don't create in root directory. */
76 /* If the user wants to, s/he can specify the maximum size of the log file,
77 * so it doesn't waste too much disk space. If the log is too fat, trim the
78 * older lines (at the top) until we're under the limit.
80 if ((gMaxLogSize
<= 0) || (Stat(gLogFileName
, &st
) < 0))
81 return; /* Never trim, or no log. */
83 if ((size_t)st
.st_size
< (size_t)gMaxLogSize
)
84 return; /* Log size not over limit yet. */
86 if ((old
= fopen(gLogFileName
, FOPEN_READ_TEXT
)) == NULL
)
89 /* Want to make it so we're about 30% below capacity.
90 * That way we won't trim the log each time we run the program.
92 fat
= (long) st
.st_size
- (long) gMaxLogSize
+ (long) (0.30 * gMaxLogSize
);
94 if (fgets(str
, (int) sizeof(str
), old
) == NULL
)
96 fat
-= (long) strlen(str
);
98 /* skip lines until a new site was opened */
100 if (fgets(str
, (int) sizeof(str
), old
) == NULL
) {
102 (void) remove(gLogFileName
);
103 return; /* Nothing left, start anew next time. */
109 /* Copy the remaining lines in "old" to "new" */
110 OurDirectoryPath(tmpLog
, sizeof(tmpLog
), "log.tmp");
111 if ((new = fopen(tmpLog
, FOPEN_WRITE_TEXT
)) == NULL
) {
115 (void) fputs(str
, new);
116 while (fgets(str
, (int) sizeof(str
), old
) != NULL
)
117 (void) fputs(str
, new);
120 if (remove(gLogFileName
) < 0)
122 if (rename(tmpLog
, gLogFileName
) < 0)