23 #ifndef _UCOMMON_FILE_H_
24 #define _UCOMMON_FILE_H_
26 #ifndef _UCOMMON_CONFIG_H_
30 #ifndef _UCOMMON_PROTOCOLS_H_
34 #ifndef _UCOMMON_THREAD_H_
38 #ifndef _UCOMMON_STRING_H_
42 #ifndef _UCOMMON_MEMORY_H_
46 #ifndef _UCOMMON_FSYS_H_
75 typedef ::fpos_t bookmark_t;
77 static file cin, cout, cerr;
91 file(
const char *path,
const char *mode,
size_t size = 2);
100 file(
const char *path,
char **argv,
const char *mode,
char **envp = NULL);
116 inline operator bool()
123 inline bool operator !()
126 inline operator FILE *()
135 void open(
const char *path,
const char *mode,
size_t size = 2);
143 void open(
const char *path,
char **argv,
const char *mode,
char **envp = NULL);
155 {
if(fp) clearerr(fp);}
169 inline size_t put(
const void *data,
size_t size)
170 {
return fp == NULL ? 0 : fwrite(data, 1, size, fp);}
172 inline size_t get(
void *data,
size_t size)
173 {
return fp == NULL ? 0 : fread(data, 1, size, fp);}
175 inline int put(
char value)
176 {
return fp == NULL ? EOF : fputc(value, fp);}
179 {
return fp == NULL ? EOF : fgetc(fp);}
181 inline int push(
char value)
182 {
return fp == NULL ? EOF : ungetc(value, fp);}
184 inline int puts(
const char *data)
185 {
return fp == NULL ? 0 : fputs(data, fp);}
187 inline char *gets(
char *data,
size_t size)
188 {
return fp == NULL ? NULL : fgets(data, size, fp);}
190 template<
typename T>
inline size_t read(T* data,
size_t count)
191 {
return fp == NULL ? 0 : fread(data,
sizeof(T), count, fp);}
193 template<
typename T>
inline size_t write(
const T* data,
size_t count)
194 {
return fp == NULL ? 0 : fwrite(data,
sizeof(T), count, fp);}
196 template<
typename T>
inline size_t read(T& data)
197 {
return fp == NULL ? 0 : fread(data,
sizeof(T), 1, fp);}
199 template<
typename T>
inline size_t write(
const T& data)
200 {
return fp == NULL ? 0 : fwrite(data,
sizeof(T), 1, fp);}
202 inline void get(bookmark_t& pos)
203 {
if(fp) fsetpos(fp, &pos);}
205 inline void set(bookmark_t& pos)
206 {
if(fp) fgetpos(fp, &pos);}
210 bool eof(
void)
const;
212 template<
typename T>
inline void offset(
long pos)
213 {
if(fp) fseek(fp,
sizeof(
const T) * pos, SEEK_CUR);}
215 inline void seek(
long offset)
216 {
if(fp) fseek(fp, offset, SEEK_SET);}
218 inline void move(
long offset)
219 {
if(fp) fseek(fp, offset, SEEK_CUR);}
221 inline void append(
void)
222 {
if (fp) fseek(fp, 0l, SEEK_END);}
224 inline void rewind(
void)
225 {
if(fp) ::rewind(fp);}
227 inline void flush(
void)
228 {
if(fp) ::fflush(fp);}
230 size_t printf(
const char *format, ...) __PRINTF(2, 3);
232 size_t scanf(const
char *format, ...) __SCANF(2, 3);
234 bool is_tty(
void) const;
Various miscellaneous platform specific headers and defines.
Common character processing protocol.
A common string class and character string support functions.
Thread-aware file system manipulation class.
Private heaps, pools, and associations.
virtual int _putch(int code)=0
Put the next character.
virtual int _getch(void)=0
Get the next character.
Access standard files through character protocol.
Thread classes and sychronization objects.
void clear(void)
Clear error state.
Abstract interfaces and support.