2007-07-09 [colin] 2.10.0cvs11
[claws.git] / src / common / w32lib.h
1 /* w32lib.h  - Posix emulation layer for Sylpheed (Claws)
2  *
3  * This file is part of w32lib.
4  *
5  * w32lib is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * w32lib is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
18  * USA.
19  *
20  * The code has been taken from the package
21  *    http://claws.sylpheed.org/win32/sylpheed/w32lib-dev-2004.2.3.0.zip
22  * on 2005-11-17 by Werner Koch <wk@gnupg.org>. There are no regular
23  * copyright notices but the file version.rc from the ZIP archive
24  * claims:
25  *
26  *     #define FILEVER "2004.2.3.0\0"
27  *     #define PRODVER "2004.2.3\0"
28  *
29  *     [...]
30  *      VALUE "FileDescription", "Posix emulation layer for Sylpheed (Claws)\0"
31  *      VALUE "FileVersion", FILEVER
32  *      VALUE "ProductVersion", PRODVER
33  *      VALUE "LegalCopyright", "GPL\0"
34  *      VALUE "CompanyName", "GNU / Free Software Foundation\0"
35  *      VALUE "ProductName", "w32lib\0"
36  *
37  * Along with the fact that Sylpheed is under the GPL we can assume
38  * that this code is under the GPL.  No author information or
39  * changelogs have been found.
40  * Files taken form the package are:
41  *    w32_dirent.c w32_reg.c w32_stat.c w32_stdlib.c w32_time.c w32_wait.c
42  *    w32_gettext.c w32_signal.c w32_stdio.c w32_string.c w32_unistd.c
43  */
44
45 /* Changes are:
46
47 2007-05-21  Werner Koch  <wk@g10code.com>
48
49         * src/common/w32_account.c: New.
50
51         * src/common/w32lib.h: Undef "interface".
52
53 2005-11-17  Werner Koch  <wk@g10code.com>
54
55         Add boilerplate text to all files and explain legal status.
56
57         * w32_reg.c: Replaced g_free and g_strdup by regular C functions.
58         (get_content_type_from_registry_with_ext): Ditto.
59         * w32_dirent.c (readdir): Ditto. 
60         (opendir): Ditto.
61         (closedir): Reformatted.
62         (readdir): Reformatted, replaced use of g_strdup_printf and other
63         g-style malloc function by regular ones.  Use DIR structure from mingw.
64         * w32lib.h: Don't define finddata_t for mingw. Replaced replacement
65         DIR structure by the one form mingw.  Allocate filename in dirent
66         statically to match the defintion ussed by mingw.
67         * w32_reg.c (read_w32_registry_string): Return error for invalid root
68         key.
69
70   */
71
72
73 #ifndef _W32LIB_H_
74 #define _W32LIB_H_
75
76 #include <windows.h>
77 #include <io.h>
78 #include <stdio.h>
79
80 #ifdef __MINGW32__
81 #include <wchar.h>
82 #include <dirent.h>
83 #endif
84
85 /* Mingw32 3.4.4 defines interface to struct and thus breaks our own
86    use of that symbol.  Undef it here. */
87 #if defined(_BASETYPS_H) && defined(interface) 
88 #undef interface
89 #endif
90
91
92 /* types */
93 /*** ??? ***/
94 #ifndef __MINGW32__
95 typedef long int off_t;
96 typedef int pid_t;
97 typedef unsigned char u_char;
98 #endif /* __MINGW32__ */
99 typedef unsigned int uid_t;
100
101 #ifndef __MINGW32__
102 /*** stat ***/
103 #define S_IRUSR _S_IREAD
104 #define S_IWUSR _S_IWRITE
105 #define S_IXUSR _S_IEXEC
106 #define S_IRWXU (_S_IREAD|_S_IWRITE|_S_IEXEC)
107 #endif /* __MINGW32__ */
108
109
110 /* (signal?) */
111 #define SIGPIPE _S_IFIFO
112
113
114 /* (directory) */
115 #define __S_ISTYPE(mode, mask)  (((mode) & _S_IFMT) == (mask))
116 #ifndef __MINGW32__
117 #define S_ISFIFO(mode)  __S_ISTYPE((mode), _S_IFIFO)
118 #define S_ISDIR(mode)   __S_ISTYPE((mode), _S_IFDIR)
119 #define S_ISREG(mode)   __S_ISTYPE((mode), _S_IFREG)
120 #endif /* __MINGW32__ */
121
122 /* functions */
123 /*** str ***/
124 int strcasecmp( const char *s1, const char *s2 );
125
126 int strncasecmp( const char *s1, const char *s2, size_t n );
127
128 /*** dir ***/
129 #ifndef __MINGW32__
130 typedef void * HANDLE;
131
132 #ifndef _FINDDATA_T_DEFINED
133 typedef unsigned long _fsize_t; /* Could be 64 bits for Win32 */
134 struct _finddata_t {
135     unsigned    attrib;
136     time_t      time_create;    /* -1 for FAT file systems */
137     time_t      time_access;    /* -1 for FAT file systems */
138     time_t      time_write;
139     _fsize_t    size;
140     char        name[260];
141 };
142 #endif /* !_FINDDATA_T_DEFINED */
143
144 struct dirent {
145         long d_ino;
146         unsigned short d_reclen;
147         unsigned short d_namlen;
148         char d_name[FILENAME_MAX];
149 };
150
151 typedef struct
152 {
153         struct _finddata_t      dd_dta;
154         struct dirent           dd_dir;
155         long                    dd_handle;
156         int                     dd_stat;
157         char                    dd_name[1];
158 } DIR;
159
160 #endif /* !__MINGW32__ */
161
162
163 DIR *opendir( const char *name );
164 int closedir( DIR *dir );
165 struct dirent *readdir( DIR *dir );
166
167 #ifdef __MINGW32__
168 struct timezone {
169   int tz_minuteswest;
170   int tz_dsttime;
171 };
172 #endif
173
174 /*** stat ***/
175 int lstat( const char *file_name, struct stat *buf );
176
177 /*** sys/wait ***/
178 pid_t waitpid( pid_t pid, int *status, int options );
179
180 /*** sys/time ***/
181 int gettimeofday( struct timeval *tv, struct timezone *tz );
182
183 /*** unistd ***/
184 uid_t getuid( void );
185 int setpgid( pid_t pid, pid_t pgid );
186 pid_t getppid( void );
187 pid_t fork( void );
188 unsigned int sleep( unsigned int seconds );
189 int link( const char *oldpath, const char *newpath );
190 int usleep( unsigned long usec );
191
192 /*** stdlib ***/
193 long int random( void );
194 void srandom( unsigned int seed );
195 int truncate( const char *path, off_t length );
196
197 /*** signal ***/
198 int kill( pid_t pid, int sig );
199
200 /*** stdio ***/
201 FILE *popen( const char *command, const char *type );
202 int pclose( FILE *stream );
203
204 /*** w32_account.c ***/
205 int w32_is_administrator (void);
206
207 /*** misc ***/
208 char *read_w32_registry_string( char *parent, char *section, char *key );
209 char *get_content_type_from_registry_with_ext( char *ext );
210
211 \f
212 /* Simulate thread-safe versions of some functions.  */
213 #define gmtime_r(time, resultp) gmtime (time)
214 #define localtime_r(time, resultp) localtime (time)
215 #define asctime_r(time, buffer) asctime (time)
216 #define ctime_r(time, buffer) ctime (time)
217
218 #endif