32 #include "dcmtk/config/osconfig.h"
33 #include "dcmtk/ofstd/oftypes.h"
34 #include "dcmtk/ofstd/ofstring.h"
35 #include "dcmtk/ofstd/ofstd.h"
37 #define INCLUDE_UNISTD
38 #define INCLUDE_CSTDIO
39 #define INCLUDE_CSTRING
40 #define INCLUDE_CSTDARG
41 #define INCLUDE_CERRNO
43 #include "dcmtk/ofstd/ofstdinc.h"
46 #ifdef HAVE_SYS_STAT_H
54 #if defined(__hpux) && defined(clearerr)
70 #ifdef _LARGEFILE64_SOURCE
73 #if !(defined(__MACH__) && defined(__APPLE__)) && !defined(__CYGWIN__)
74 #define EXPLICIT_LFS_64
78 #if defined(_WIN32) && !defined(__MINGW32__)
81 typedef __int64 offile_off_t;
82 typedef fpos_t offile_fpos_t;
84 #ifdef EXPLICIT_LFS_64
86 typedef fpos64_t offile_fpos_t;
87 typedef off64_t offile_off_t;
91 typedef off_t offile_off_t;
93 typedef long offile_off_t;
95 typedef fpos_t offile_fpos_t;
100 typedef int offile_errno_t;
139 OFBool
fopen(
const char *filename,
const char *modes)
142 #ifdef EXPLICIT_LFS_64
143 file_ = :: fopen64(filename, modes);
145 file_ = STDIO_NAMESPACE
fopen(filename, modes);
148 return (
file_ != NULL);
151 #if defined(WIDE_CHAR_FILE_IO_FUNCTIONS) && defined(_WIN32)
158 OFBool wfopen(
const wchar_t *filename,
const wchar_t *modes)
161 file_ = _wfopen(filename, modes);
163 return (
file_ != NULL);
184 return (
file_ != NULL);
196 OFBool
popen(
const char *command,
const char *modes)
200 file_ = _popen(command, modes);
205 return (
file_ != NULL);
217 OFBool
freopen(
const char *filename,
const char *modes)
219 #if defined(EXPLICIT_LFS_64) && ! defined(__MINGW32__)
226 return (
file_ != NULL);
237 #if defined(EXPLICIT_LFS_64) && ! defined(__MINGW32__)
239 file_ = :: tmpfile64();
244 return (
file_ != NULL);
262 result = _pclose(
file_);
294 size_t fwrite(
const void *ptr,
size_t size,
size_t n)
296 return STDIO_NAMESPACE
fwrite(ptr, size, n,
file_);
310 size_t fread(
void *ptr,
size_t size,
size_t n)
312 return STDIO_NAMESPACE
fread(ptr, size, n,
file_);
348 #if defined(_WIN32) || defined(__hpux)
349 this->
setvbuf(NULL, _IOLBF, 0);
377 return STDIO_NAMESPACE feof(
file_);
391 return ferror(
file_);
393 return STDIO_NAMESPACE ferror(
file_);
441 int result = STDIO_NAMESPACE
setvbuf(
file_, buf, modes, n);
462 #if defined(_WIN32) || defined(__hpux)
463 this->
setvbuf(NULL, buf ? _IOFBF : _IONBF, size);
510 int fseek(offile_off_t off,
int whence)
517 offile_fpos_t off2 = off;
530 if (_lseeki64( fileno(
file_), 0, 2) == -1)
532 if (_lseeki64(:: fileno(
file_), 0, 2) == -1)
542 if (_fstati64( fileno(
file_), &buf) == -1)
544 if (_fstati64(:: fileno(
file_), &buf) == -1)
569 #elif defined(__BEOS__)
570 result = :: _fseek(fp, offset, whence);
573 #ifdef EXPLICIT_LFS_64
574 result = :: fseeko64(
file_, off, whence);
576 result = :: fseeko(
file_, off, whence);
579 result = STDIO_NAMESPACE
fseek(
file_, off, whence);
606 #ifdef EXPLICIT_LFS_64
607 result = :: ftello64(
file_);
609 result = :: ftello(
file_);
629 #if defined(EXPLICIT_LFS_64) && ! defined(__MINGW32__)
631 result = :: fgetpos64(
file_, pos);
649 #if defined(EXPLICIT_LFS_64) && ! defined(__MINGW32__)
651 result = :: fsetpos64(
file_, pos);
668 va_start(ap, format);
714 #ifdef WIDE_CHAR_FILE_IO_FUNCTIONS
735 return STDIO_NAMESPACE fwide(
file_, mode);
746 wint_t result = STDIO_NAMESPACE fgetwc(
file_);
757 wint_t fputwc(
wchar_t wc)
759 wint_t result = STDIO_NAMESPACE fputwc(wc,
file_);
778 wint_t ungetwc(wint_t wc)
780 wint_t result = STDIO_NAMESPACE ungetwc(wc,
file_);
790 int fwprintf(
const wchar_t *format, ...)
794 va_start(ap, format);
795 result = STDIO_NAMESPACE vfwprintf(
file_, format, ap);
805 int vfwprintf(
const wchar_t *format, va_list arg)
807 return STDIO_NAMESPACE vfwprintf(
file_, format, arg);
this class provides a simple C++ encapsulation layer for stdio FILE pointers.
int error()
tests the error indicator for the stream, returning non-zero if it is set.
int vfprintf(const char *format, va_list arg)
print formatted string into stream, see printf(3)
size_t fwrite(const void *ptr, size_t size, size_t n)
writes n elements of data, each size bytes long, to the stream, obtaining them from the location give...
int fgetc()
reads the next character from stream and returns it as an unsigned char cast to an int...
void storeLastError()
store last error code. For now we simply store the content of errno.
int fflush()
forces a write of all user-space buffered data for the given output or update stream via the stream's...
void setbuffer(char *buf, size_t size)
The three types of buffering available are unbuffered, block buffered, and line buffered.
int fgetpos(offile_fpos_t *pos)
alternate interface equivalent to ftell, storing the current value of the file offset into the object...
void setbuf(char *buf)
The three types of buffering available are unbuffered, block buffered, and line buffered.
FILE * file_
the file maintained by this object
void clearerr()
clears the end-of-file and error indicators for the stream
OFBool tmpfile()
generates a unique temporary filename.
offile_errno_t getLastError() const
return last error code for this stream
int setvbuf(char *buf, int modes, size_t n)
The three types of buffering available are unbuffered, block buffered, and line buffered.
static const char * strerror(const int errnum, char *buf, const size_t buflen)
convert a given error code to a string.
OFBool open() const
return true if this object is currently associated with a stream, false otherwise ...
OFBool fdopen(int fd, const char *modes)
associates a stream with the existing file descriptor, fildes.
int pclose()
waits for the associated process (created with popen) to terminate and returns the exit status of the...
int fileNo()
returns the low-level file descriptor associated with the stream.
int fputs(const char *s)
writes the string s to stream, without its trailing '\0'.
OFBool freopen(const char *filename, const char *modes)
opens the file whose name is the string pointed to by path and associates the stream pointed maintain...
OFFile()
default constructor, creates an object that is not associated with any file.
int fsetpos(offile_fpos_t *pos)
alternate interface equivalent to fseek (with whence set to SEEK_SET), setting the current value of t...
~OFFile()
destructor. Closes file if still open.
offile_off_t ftell()
obtains the current value of the file position indicator for the stream pointed to by the stream...
offile_errno_t lasterror_
the last error code for operations of this stream
int fprintf(const char *format,...)
print formatted string into stream, see printf(3)
int fclose()
dissociates the named stream from its underlying file or set of functions.
char * fgets(char *s, int n)
reads in at most one less than n characters from stream and stores them into the buffer pointed to by...
OFBool popen(const char *command, const char *modes)
opens a process by creating a pipe, forking, and invoking the shell.
OFBool fopen(const char *filename, const char *modes)
opens the file whose name is the string pointed to by path and associates a stream with it...
OFBool popened_
a flag indicating whether or not this object was created with popen().
FILE * file()
return FILE pointer managed by this object.
int fputc(int c)
writes the character c, cast to an unsigned char, to stream.
void getLastErrorString(OFString &s) const
return string describing last error code for this stream
OFFile(FILE *f)
create object for given stdio FILE
void setlinebuf()
The three types of buffering available are unbuffered, block buffered, and line buffered.
a simple string class that implements a subset of std::string.
int eof() const
tests the end-of-file indicator for the stream, returning non-zero if it is set.
void rewind()
sets the file position indicator for the stream pointed to by stream to the beginning of the file...
size_t fread(void *ptr, size_t size, size_t n)
reads n elements of data, each size bytes long, from the stream, storing them at the location given b...
int fseek(offile_off_t off, int whence)
sets the file position indicator for the stream pointed to by stream.
int ungetc(int c)
pushes c back to stream, cast to unsigned char, where it is available for subsequent read operations...