Debian Codegraph @

inc/gfile.h

raw symbols SCIP
1 /* Copyright (C) 2000-2012 by George Williams */
2 /*
3 * Redistribution and use in source and binary forms, with or without
4 * modification, are permitted provided that the following conditions are met:
5
6 * Redistributions of source code must retain the above copyright notice, this
7 * list of conditions and the following disclaimer.
8
9 * Redistributions in binary form must reproduce the above copyright notice,
10 * this list of conditions and the following disclaimer in the documentation
11 * and/or other materials provided with the distribution.
12
13 * The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28 #ifndef FONTFORGE_GFILE_H
29 #define FONTFORGE_GFILE_H
30
31 #include "basics.h"
32
33 #include <stdio.h>
34 #include <time.h>
35
36 /* For stat compatibility - must include sys/types.h before sys/stat.h */
37 #include <sys/types.h>
38 #include <sys/stat.h>
39
40 /* For mode_t (not defined by MSVC) */
41 #ifdef _MSC_VER
42 typedef unsigned short mode_t;
43 #endif
44
45 #ifdef _MSC_VER
46 typedef struct __stat64 ff_stat_t;
47 #define ff_stat(p, b) _stat64(p, b)
48 #define ff_fstat(f, b) _fstat64(f, b)
49 #else
50 typedef struct stat ff_stat_t;
51 #define ff_stat(p, b) stat(p, b)
52 #define ff_fstat(f, b) fstat(f, b)
53 #endif
54
55 /* home directories for fontforge */
56 enum { Cache, Config, Data };
57
58 #ifdef __cplusplus
59 extern "C" {
60 #endif
61
62 int mkdir_p(const char *path, mode_t mode);
63
64 extern char *GFileNormalizePath(char *path);
65 extern unichar_t *u_GFileNormalizePath(unichar_t *path);
66
67 extern char* GFileGetHomeDir(void);
68 extern unichar_t* u_GFileGetHomeDir(void);
69
70 extern char *GFileRemoveExtension(char *path);
71 extern char *GFileGetAbsoluteName(const char *name);
72 extern char *GFileBuildName(char *dir,char *fname,char *buffer,size_t size);
73 extern char *GFileReplaceName(char *oldname,char *fname,char *buffer,size_t size);
74 /**
75 * Return the file name for the full path 'path'. This is like the
76 * shell "basename" command, for example:
77 * GFileBaseName("/a/b/c/foo.sfd") returns "foo.sfd".
78 *
79 * You might be looking for GFileBaseName(), this function does basename from the shell.
80 *
81 * The return value is a pointer either being the same as path or a
82 * pointer into the string that path points to. So no memory is
83 * allocated by this function and the return value is dependent on the
84 * 'path' string you passed in.
85 */
86 extern char *GFileNameTail(const char *oldname);
87 extern char *GFileAppendFile(char *dir,char *name,int isdir);
88 extern int GFileIsAbsolute(const char *file);
89 extern int GFileIsDir(const char *file);
90 /**
91 * Returns true if the file exists
92 */
93 extern int GFileExists(const char *file);
94 extern int GFileModifyable(const char *file);
95 extern int GFileModifyableDir(const char *file);
96 extern int GFileReadable(const char *file);
97 extern FILE* GFileTmpfile();
98 extern int GFileRemove(const char *path, int recursive);
99 extern int GFileMkDir(const char *name, int mode);
100 extern int GFileRmDir(const char *name);
101 extern int GFileUnlink(const char *name);
102 extern char* GFileMimeType(const char *path);
103 extern unichar_t *u_GFileBuildName(unichar_t *dir,unichar_t *fname,unichar_t *buffer,int size);
104 extern unichar_t *u_GFileReplaceName(unichar_t *oldname,unichar_t *fname,unichar_t *buffer,int size);
105 extern unichar_t *u_GFileNameTail(const unichar_t *oldname);
106 extern unichar_t *u_GFileNormalize(unichar_t *name);
107 extern unichar_t *u_GFileAppendFile(unichar_t *dir,unichar_t *name,int isdir);
108 extern int u_GFileIsAbsolute(const unichar_t *file);
109 extern int u_GFileIsDir(const unichar_t *file);
110 extern int u_GFileExists(const unichar_t *file);
111 extern int u_GFileModifyable(const unichar_t *file);
112 extern int u_GFileModifyableDir(const unichar_t *file);
113 extern int u_GFileReadable(unichar_t *file);
114 extern int u_GFileMkDir(unichar_t *name);
115 extern int u_GFileRmDir(unichar_t *name);
116 extern int u_GFileUnlink(unichar_t *name);
117 extern off_t GFileGetSize(char *name);
118 extern off_t GFileGetSizeF(FILE *file);
119 extern time_t GFileGetMTime(const char *name);
120 extern time_t GFileGetMTimeF(FILE *file);
121 extern char *GFileReadAll(char *name);
122 extern int GFileWriteAll(char *filepath, char *data);
123 extern void FindProgRoot(const char *prog);
124 extern const char *getShareDir();
125 extern const char *getLocaleDir(void);
126 extern const char *getPixmapDir(void);
127 extern const char *getHelpDir(void);
128 extern const char *getUserHomeDir(void);
129 extern char *getFontForgeUserDir(int dir);
130
131 /**
132 * This is the full path of ~ on OSX and Linux
133 * and something like c:\Users\foo\Documents on windows
134 */
135 extern char *GFileGetHomeDocumentsDir(void);
136 extern unichar_t* u_GFileGetHomeDocumentsDir(void);
137
138 /**
139 * Return the directory name for the full path 'path'.
140 * This is like the shell "dirname" command, for example:
141 * GFileDirName("/a/b/c/foo.sfd") returns "/a/b/c/".
142 * This will also handle mingw paths as expected.
143 * A trailing slash is always appended.
144 *
145 * The return value must be freed.
146 */
147 extern char *GFileDirName(const char *path);
148
149 /**
150 * Exactly like GFileDirName, but optionally treats the path as if
151 * it were a file. This is needed for cases of treating UFO and sfdir folders as
152 * 'files'.
153 */
154 extern char *GFileDirNameEx(const char *path, int treat_as_file);
155
156 /**
157 * Get the $libexec directory for the installation. As this is only
158 * used at the moment on non windows machines and has not been tested
159 * on a mingw build, I have added the nonwindows postfix. When the
160 * function is needed on Windows then the postfix should be dropped.
161 *
162 * The return value must NOT be freed.
163 **/
164 extern char* getLibexecDir_NonWindows(void);
165
166 #ifdef __cplusplus
167 }
168 #endif
169
170 #endif /* FONTFORGE_GFILE_H */