ReactOS 0.4.16-dev-297-gc569aee
log.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define kLogFileName   "log"
 

Functions

void EndLog (void)
 
void InitLog (void)
 
void LogOpen (const char *const host)
 
void LogXfer (const char *const mode, const char *const url)
 

Macro Definition Documentation

◆ kLogFileName

#define kLogFileName   "log"

Definition at line 11 of file log.h.

Function Documentation

◆ EndLog()

void EndLog ( void  )

Definition at line 65 of file log.c.

66{
67 FILE *new, *old;
68 struct Stat st;
69 long fat;
70 char str[512];
71 char tmpLog[256];
72
73 if (gOurDirectoryPath[0] == '\0')
74 return; /* Don't create in root directory. */
75
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.
79 */
80 if ((gMaxLogSize <= 0) || (Stat(gLogFileName, &st) < 0))
81 return; /* Never trim, or no log. */
82
83 if ((size_t)st.st_size < (size_t)gMaxLogSize)
84 return; /* Log size not over limit yet. */
85
86 if ((old = fopen(gLogFileName, FOPEN_READ_TEXT)) == NULL)
87 return;
88
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.
91 */
92 fat = (long) st.st_size - (long) gMaxLogSize + (long) (0.30 * gMaxLogSize);
93 while (fat > 0L) {
94 if (fgets(str, (int) sizeof(str), old) == NULL)
95 return;
96 fat -= (long) strlen(str);
97 }
98 /* skip lines until a new site was opened */
99 for (;;) {
100 if (fgets(str, (int) sizeof(str), old) == NULL) {
101 (void) fclose(old);
103 return; /* Nothing left, start anew next time. */
104 }
105 if (! isspace(*str))
106 break;
107 }
108
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) {
112 (void) fclose(old);
113 return;
114 }
115 (void) fputs(str, new);
116 while (fgets(str, (int) sizeof(str), old) != NULL)
117 (void) fputs(str, new);
118 (void) fclose(old);
119 (void) fclose(new);
120 if (remove(gLogFileName) < 0)
121 return;
122 if (rename(tmpLog, gLogFileName) < 0)
123 return;
124} /* EndLog */
#define isspace(c)
Definition: acclib.h:69
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
#define NULL
Definition: types.h:112
_Check_return_opt_ _CRTIMP int __cdecl fputs(_In_z_ const char *_Str, _Inout_ FILE *_File)
_Check_return_ _CRTIMP FILE *__cdecl fopen(_In_z_ const char *_Filename, _In_z_ const char *_Mode)
_Check_return_opt_ _CRTIMP char *__cdecl fgets(_Out_writes_z_(_MaxCount) char *_Buf, _In_ int _MaxCount, _Inout_ FILE *_File)
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
#define Stat
Definition: syshdrs.h:78
static unsigned char * fat
Definition: mkdosfs.c:542
int gMaxLogSize
Definition: pref.c:53
char gLogFileName[256]
Definition: log.c:14
char gOurDirectoryPath[]
Definition: util.c:17
char * OurDirectoryPath(char *const dst, const size_t siz, const char *const fname)
Definition: util.c:486
int remove
Definition: msacm.c:1366
#define FOPEN_READ_TEXT
Definition: syshdrs.h:82
#define FOPEN_WRITE_TEXT
Definition: syshdrs.h:83
#define L(x)
Definition: ntvdm.h:50
#define long
Definition: qsort.c:33
const WCHAR * str
_Check_return_ int __cdecl rename(_In_z_ const char *_OldFilename, _In_z_ const char *_NewFilename)

Referenced by PostShell().

◆ InitLog()

void InitLog ( void  )

Definition at line 20 of file log.c.

21{
23} /* InitLog */
#define kLogFileName
Definition: log.h:11

Referenced by DoTest(), and PreInit().

◆ LogOpen()

void LogOpen ( const char *const  host)

Definition at line 45 of file log.c.

46{
47 time_t now;
48 FILE *fp;
49
50 if (gMaxLogSize == 0)
51 return; /* Don't log */
52
53 time(&now);
55 if (fp != NULL) {
56 (void) fprintf(fp, "%s at %s", host, ctime(&now));
57 (void) fclose(fp);
58 }
59} /* LogOpen */
__kernel_time_t time_t
Definition: linux.h:252
time_t now
Definition: finger.c:65
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
__u16 ctime
Definition: mkdosfs.c:4
__u16 time
Definition: mkdosfs.c:8
#define FOPEN_APPEND_TEXT
Definition: syshdrs.h:84
char * host
Definition: whois.c:55

Referenced by DoOpen().

◆ LogXfer()

void LogXfer ( const char *const  mode,
const char *const  url 
)

Definition at line 28 of file log.c.

29{
30 FILE *fp;
31
32 if (gMaxLogSize == 0)
33 return; /* Don't log */
34
36 if (fp != NULL) {
37 (void) fprintf(fp, " %s %s\n", mode, url);
38 (void) fclose(fp);
39 }
40} /* LogOpen */
GLenum mode
Definition: glext.h:6217
static const WCHAR url[]
Definition: encode.c:1432

Referenced by PrPhilBar(), PrSizeAndRateMeter(), and PrStatBar().