HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SYS_Stdio.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: SYS_Stdio.h (SYS Library, C++)
7  *
8  * COMMENTS: Platform-independent wrappers for functions in <stdio.h>
9  */
10 
11 #pragma once
12 
13 #ifndef __SYS_STDIO_H_INCLUDED__
14 #define __SYS_STDIO_H_INCLUDED__
15 
16 /// @file SYS_Stdio.h
17 /// Portable stdio.h replacements, primarily breaking broken Windows
18 /// implementations.
19 
20 #include "SYS_API.h"
21 #include "SYS_Inline.h"
22 #include "SYS_Types.h"
23 
24 #include <stdio.h>
25 
26 #ifndef _WIN32
27 #include <unistd.h> // for rmdir()
28 #endif
29 
30 /// @internal
31 #if SYS_HEADER_ONLY
32  #include "SYS_Stdio.C"
33 #elif defined(_WIN32)
34  SYS_API extern FILE *SYSfopenNT(const char *filename, const char *mode);
35  SYS_API extern int SYSremoveNT(const char *path);
36  SYS_API extern int SYSrmdirNT(const char *path);
37 #endif
38 
39 /// Portable replacement for fopen() to allow UTF-8 paths on Windows
40 static inline FILE*
41 SYSfopen(const char *filename, const char *mode)
42 {
43 #ifdef _WIN32
44  return SYSfopenNT(filename, mode);
45 #else
46  return fopen(filename, mode);
47 #endif
48 }
49 
50 /// Portable replacement for remove() to allow UTF-8 paths on Windows.
51 /// Unlike the CRT remove(), we satisfy the POSIX requirement that if path
52 /// is a directory, then it's equivalent to calling rmdir(path),
53 static inline int
54 SYSremove(const char *path)
55 {
56 #ifdef _WIN32
57  return SYSremoveNT(path);
58 #else
59  return remove(path);
60 #endif
61 }
62 
63 /// Portable replacement for rmdir() to allow UTF-8 paths on Windows
64 static inline int
65 SYSrmdir(const char *path)
66 {
67 #ifdef _WIN32
68  return SYSrmdirNT(path);
69 #else
70  return rmdir(path);
71 #endif
72 }
73 
74 /// Portable replacement for fseek() to use 64-bit file offsets
75 static inline int
76 SYSfseek(FILE *stream, int64 offset, int whence)
77 {
78 #ifdef _WIN32
79  return _fseeki64(stream, offset, whence);
80 #else
81  // fseeko uses 64-bit offsets even on 32-bit platforms when
82  // _FILE_OFFSET_BITS is defined as 64.
83  return fseeko(stream, offset, whence);
84 #endif
85 }
86 
87 /// Portable replacement for ftell() to return 64-bit file offsets
88 static inline int64
89 SYSftell(FILE *stream)
90 {
91 #ifdef _WIN32
92  return _ftelli64(stream);
93 #else
94  // ftello uses 64-bit offsets even on 32-bit platforms when
95  // _FILE_OFFSET_BITS is defined as 64.
96  return ftello(stream);
97 #endif
98 }
99 
100 #endif // __SYS_STDIO_H_INCLUDED__
GLuint GLuint stream
Definition: glcorearb.h:1832
GT_API const UT_StringHolder filename
GLsizei const GLchar *const * path
Definition: glcorearb.h:3341
GLintptr offset
Definition: glcorearb.h:665
OIIO_UTIL_API FILE * fopen(string_view path, string_view mode)
Version of fopen that can handle UTF-8 paths even on Windows.
long long int64
Definition: SYS_Types.h:116
GLenum mode
Definition: glcorearb.h:99
#define SYS_API
Definition: SYS_API.h:11