ReactOS 0.4.16-dev-2104-gb84fa49
util.h File Reference
#include <stdio.h>
#include "cmd.h"
#include "options.h"
Include dependency graph for util.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define log(outFile, fmt, ...)
 
#define esclog(outFile, fmt, ...)
 
#define clilog(outFile, fmt, ...)
 
#define l2l_dbg(level, ...)
 

Functions

int file_exists (char *name)
 
int mkPath (char *path, int isDir)
 
charbasename (char *path)
 
const chargetFmt (const char *a)
 
long my_atoi (const char *a)
 
int isOffset (const char *a)
 
int copy_file (char *src, char *dst)
 
int set_LogFile (FILE **plogFile)
 

Macro Definition Documentation

◆ clilog

#define clilog (   outFile,
  fmt,
  ... 
)
Value:
{ \
if (opt_cli) \
esclog(outFile, fmt, ##__VA_ARGS__) \
else \
log(outFile, fmt, ##__VA_ARGS__); \
}
int opt_cli
Definition: options.c:31
Definition: dsound.c:943

Definition at line 27 of file util.h.

◆ esclog

#define esclog (   outFile,
  fmt,
  ... 
)
Value:
{ \
log(outFile, KDBG_ESC_RESP fmt, ##__VA_ARGS__); \
}
#define KDBG_ESC_RESP
Definition: cmd.h:15

Definition at line 22 of file util.h.

◆ l2l_dbg

#define l2l_dbg (   level,
  ... 
)
Value:
{ \
if (opt_verbose >= level) \
fprintf(stderr, ##__VA_ARGS__); \
}
#define stderr
GLint level
Definition: gl.h:1546
int opt_verbose
Definition: options.c:25

Definition at line 35 of file util.h.

◆ log

#define log (   outFile,
  fmt,
  ... 
)
Value:
{ \
fprintf(outFile, fmt, ##__VA_ARGS__); \
if (logFile) \
fprintf(logFile, fmt, ##__VA_ARGS__); \
}
char logFile[_MAX_PATH]
Definition: tftpd.cpp:38

Definition at line 15 of file util.h.

Function Documentation

◆ basename()

char * basename ( char path)

Definition at line 110 of file util.c.

111{
112 char *base;
113
115 if (base)
116 return ++base;
117 return path;
118}
_ACRTIMP char *__cdecl strrchr(const char *, int)
Definition: string.c:3298
#define PATH_CHAR
Definition: rmkdir.c:17

◆ copy_file()

int copy_file ( char src,
char dst 
)

Definition at line 163 of file util.c.

164{
165 char Line[LINESIZE];
166
168 l2l_dbg(2, "Executing: %s\n", Line);
169 remove(dst);
170 if (file_exists(dst))
171 {
172 l2l_dbg(0, "Cannot remove dst %s before copy\n", dst);
173 return 1;
174 }
175 if (system(Line) < 0)
176 {
177 l2l_dbg(0, "Cannot copy %s to %s\n", src, dst);
178 l2l_dbg(1, "Failed to execute: '%s'\n", Line);
179 return 2;
180 }
181
182 if (!file_exists(dst))
183 {
184 l2l_dbg(0, "Dst %s does not exist after copy\n", dst);
185 return 2;
186 }
187 return 0;
188}
#define LINESIZE
Definition: chargen.c:18
_ACRTIMP int __cdecl system(const char *)
Definition: process.c:1297
GLenum src
Definition: glext.h:6340
GLenum GLenum dst
Definition: glext.h:6340
#define sprintf
Definition: sprintf.c:45
int remove
Definition: msacm.c:1366
#define CP_FMT
Definition: config.h:16
int file_exists(char *name)
Definition: util.c:52
#define l2l_dbg(level,...)
Definition: util.h:35
Definition: ncftp.h:79

◆ file_exists()

int file_exists ( char name)

Definition at line 52 of file util.c.

53{
54 FILE *f;
55
56 f = fopen(name, "r");
57 if (!f)
58 return 0;
59 fclose(f);
60 return 1;
61}
int CDECL fclose(FILE *file)
Definition: file.c:3757
FILE *CDECL fopen(const char *path, const char *mode)
Definition: file.c:4310
GLfloat f
Definition: glext.h:7540
#define f
Definition: ke_i.h:83
Definition: name.c:39

Referenced by copy_file().

◆ getFmt()

const char * getFmt ( const char a)

Definition at line 121 of file util.c.

122{
123 const char *fmt = "%x";
124
125 if (*a == '0')
126 {
127 switch (*++a)
128 {
129 case 'x':
130 fmt = "%x";
131 ++a;
132 break;
133 case 'd':
134 fmt = "%d";
135 ++a;
136 break;
137 default:
138 fmt = "%o";
139 break;
140 }
141 }
142 return fmt;
143}
GLboolean GLboolean GLboolean GLboolean a
Definition: glext.h:6204
#define a
Definition: ke_i.h:78

Referenced by isOffset(), and my_atoi().

◆ isOffset()

int isOffset ( const char a)

Definition at line 154 of file util.c.

155{
156 int i = 0;
157 if (strchr(a, '.'))
158 return 0;
159 return sscanf(a, getFmt(a), &i);
160}
_ACRTIMP int __cdecl _ACRTIMP int __cdecl _ACRTIMP int __cdecl _ACRTIMP int __cdecl _ACRTIMP int __cdecl _ACRTIMP int __cdecl _ACRTIMP int __cdecl sscanf(const char *, const char *,...) __WINE_CRT_SCANF_ATTR(2
_ACRTIMP char *__cdecl strchr(const char *, int)
Definition: string.c:3286
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
const char * getFmt(const char *a)
Definition: util.c:121

Referenced by main().

◆ mkPath()

int mkPath ( char path,
int  isDir 
)

Definition at line 68 of file util.c.

69{
70 char *s;
71 int res = 0;
72
73 if (isDir)
74 {
75 res = MKDIR(path);
76 if (!res || (res == -1 && errno == EEXIST))
77 return 0;
78 }
79 // create parent dir
80 if ((s = strrchr(path, PATH_CHAR)))
81 {
82 *s = '\0';
83 res = mkPath(path, 1);
84 *s = PATH_CHAR;
85 }
86
87 if (!res && isDir)
88 res = MKDIR(path);
89
90 return res;
91}
#define EEXIST
Definition: errno.h:39
#define errno
Definition: errno.h:120
GLdouble s
Definition: gl.h:2039
GLuint res
Definition: glext.h:9613
#define MKDIR(d)
Definition: compat.h:27
int mkPath(char *path, int isDir)
Definition: util.c:68

Referenced by mkPath().

◆ my_atoi()

long my_atoi ( const char a)

Definition at line 146 of file util.c.

147{
148 int i = 0;
149 sscanf(a, getFmt(a), &i);
150 return i;
151}

Referenced by main().

◆ set_LogFile()

int set_LogFile ( FILE **  plogFile)

Definition at line 19 of file util.c.

20{
21 if (*opt_logFile)
22 {
23 if (*plogFile)
24 fclose(*plogFile);
25 *plogFile = NULL;
26
27 if (strcmp(opt_logFile,"none") == 0)
28 return 0; //just close
29
30 *plogFile = fopen(opt_logFile, opt_mod ? opt_mod : "a");
31 if (*plogFile)
32 {
33 // disable buffering so fflush is not needed
34 if (!opt_buffered)
35 {
36 l2l_dbg(1, "Disabling log buffering on %s\n", opt_logFile);
37 setbuf(*plogFile, NULL);
38 }
39 else
40 l2l_dbg(1, "Enabling log buffering on %s\n", opt_logFile);
41 }
42 else
43 {
44 l2l_dbg(0, "Could not open logfile %s (%s)\n", opt_logFile, strerror(errno));
45 return 2;
46 }
47 }
48 return 0;
49}
#define NULL
Definition: types.h:112
char *CDECL strerror(int err)
Definition: errno.c:273
void CDECL setbuf(FILE *file, char *buf)
Definition: file.c:5046
_ACRTIMP int __cdecl strcmp(const char *, const char *)
Definition: string.c:3319
char * opt_mod
Definition: options.c:42
int opt_buffered
Definition: options.c:21
char opt_logFile[PATH_MAX]
Definition: options.c:41

Referenced by handle_escape_cmd(), and main().