Match also UNC paths on Win32.
[platform/upstream/glib.git] / gwin32.h
1 /* GLIB - Library of useful routines for C programming
2  * Copyright (C) 1995-1997  Peter Mattis, Spencer Kimball and Josh MacDonald
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 /*
21  * Modified by the GLib Team and others 1997-2000.  See the AUTHORS
22  * file for a list of people on the GLib Team.  See the ChangeLog
23  * files for a list of changes.  These files are distributed with
24  * GLib at ftp://ftp.gtk.org/pub/gtk/. 
25  */
26
27 #ifndef __G_WIN32_H__
28 #define __G_WIN32_H__
29
30 #include <gtypes.h>
31
32 #ifdef G_OS_WIN32
33
34 /* Windows emulation stubs for common Unix functions
35  */
36
37 G_BEGIN_DECLS
38
39 #define MAXPATHLEN 1024
40
41 #ifdef _MSC_VER
42 typedef int pid_t;
43 #endif
44
45 /*
46  * To get prototypes for the following POSIXish functions, you have to
47  * include the indicated non-POSIX headers. The functions are defined
48  * in OLDNAMES.LIB (MSVC) or -lmoldname-msvc (mingw32).
49  *
50  * getcwd: <direct.h> (MSVC), <io.h> (mingw32)
51  * getpid: <process.h>
52  * access: <io.h>
53  * unlink: <stdio.h> or <io.h>
54  * open, read, write, lseek, close: <io.h>
55  * rmdir: <direct.h>
56  * pipe: <direct.h>
57  */
58
59 /* pipe is not in OLDNAMES.LIB or -lmoldname-msvc. */
60 #define pipe(phandles)  _pipe (phandles, 4096, _O_BINARY)
61
62 /* For some POSIX functions that are not provided by the MS runtime,
63  * we provide emulators in glib, which are prefixed with g_win32_.
64  */
65 #    define ftruncate(fd, size) g_win32_ftruncate (fd, size)
66
67 /* -lmingw32 also has emulations for these, but we need our own
68  * for MSVC anyhow, so we might aswell use them always.
69  */
70 #    define opendir             g_win32_opendir
71 #    define readdir             g_win32_readdir
72 #    define rewinddir           g_win32_rewinddir
73 #    define closedir            g_win32_closedir
74 #    define NAME_MAX 255
75
76 struct dirent
77 {
78   gchar  d_name[NAME_MAX + 1];
79 };
80
81 struct DIR
82 {
83   gchar        *dir_name;
84   gboolean      just_opened;
85   guint         find_file_handle;
86   gpointer      find_file_data;
87   struct dirent readdir_result;
88 };
89 typedef struct DIR DIR;
90
91 /* emulation functions */
92 extern int      g_win32_ftruncate       (gint            f,
93                                          guint           size);
94 DIR*            g_win32_opendir         (const gchar    *dirname);
95 struct dirent*  g_win32_readdir         (DIR            *dir);
96 void            g_win32_rewinddir       (DIR            *dir);
97 gint            g_win32_closedir        (DIR            *dir);
98
99 /* The MS setlocale uses locale names of the form "English_United
100  * States.1252" etc. We want the Unixish standard form "en", "zh_TW"
101  * etc. This function gets the current thread locale from Windows and
102  * returns it as a string of the above form for use in forming file
103  * names etc. The returned string should be deallocated with g_free().
104  */
105 gchar*          g_win32_getlocale  (void);
106
107 /* Translate a Win32 error code (as returned by GetLastError()) into
108  * the corresponding message. The returned string should be deallocated
109  * with g_free().
110  */
111 gchar*          g_win32_error_message (gint error);
112
113 gchar*          g_win32_get_package_installation_directory (gchar *package,
114                                                             gchar *dll_name);
115
116 gchar*          g_win32_get_package_installation_subdirectory (gchar *package,
117                                                                gchar *dll_name,
118                                                                gchar *subdir);
119
120 G_END_DECLS
121
122 #endif   /* G_OS_WIN32 */
123
124 #endif /* __G_WIN32_H__ */