#include "config.h"
#include "intsym.h"
#include <errno.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <signal.h>
#include <unistd.h>
#include <sys/types.h>
#include <inttypes.h>
#include <stdint.h>
#include <limits.h>
#include <string.h>
#include <strings.h>
#include <sys/time.h>
#include <fcntl.h>
#include "true.h"
Go to the source code of this file.
|
void * | safe_realloc (void *ptr, size_t size) |
|
char * | compat_strdup (const char *s) |
|
char * | compat_getenv (const char *name) |
|
int | compat_open (const char *filename, int flags) |
|
FILE * | compat_fopen (const char *filename, const char *mode) |
|
FILE * | compat_fdopen (int fd, const char *mode) |
|
int | compat_close (int infd) |
|
int | compat_fclose (FILE *stream) |
|
int | win32_wide_utf8 (const wchar_t *const wptr, char **mbptr, size_t *buflen) |
|
int | win32_utf8_wide (const char *const mbptr, wchar_t **wptr, size_t *buflen) |
|
char * | compat_catpath (const char *prefix, const char *path) |
|
int | compat_isdir (const char *path) |
|
struct compat_dir * | compat_diropen (char *path) |
|
void | compat_dirclose (struct compat_dir *) |
|
char * | compat_nextfile (struct compat_dir *) |
|
char * | compat_nextdir (struct compat_dir *) |
|
size_t | unintr_write (int fd, void const *buffer, size_t bytes) |
|
size_t | unintr_read (int fd, void *buffer, size_t bytes) |
|
size_t | unintr_fwrite (const void *ptr, size_t size, size_t nmemb, FILE *stream) |
|
◆ atobigint
◆ inline
◆ OFF_P
◆ SIZE_MAX
◆ SIZE_P
◆ SSIZE_MAX
◆ SSIZE_P
◆ ULONG_MAX
◆ byte
◆ off_p
◆ size_p
◆ ssize_p
◆ compat_catpath()
Definition at line 324 of file compat.c.
325{
327#ifdef WANT_WIN32_UNICODE
328 wchar_t *wprefix =
NULL;
329 wchar_t *wpath =
NULL;
330 wchar_t *locwret =
NULL;
331
332
333
334
335
336
337
341
343 goto catpath_end;
344 wprefix = u2wpath(prefix);
345 wpath = u2wpath(
path);
346 if((prefix && !wprefix) || (
path && !wpath))
347 goto catpath_end;
348
349
350
353 if(mypac)
354 {
355 debug(
"Actually calling PathAllocCombine!");
356 mypac(wprefix, wpath, 1, &locwret);
357 }
358 else
359 {
360
361
363 if(locwret)
365 }
366 ret = w2upath(locwret);
367
368catpath_end:
372#else
373 size_t len, prelen, patlen;
374
377 prelen = prefix ?
strlen(prefix) : 0;
379
380 len = ((prefix &&
path) ? 1 : 0) + prelen + patlen;
383 {
384 size_t off=0;
387 ret[prelen+(off++)] =
'/';
390 }
391#endif
393}
ACPI_SIZE strlen(const char *String)
#define GetProcAddress(x, y)
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
HLOCAL NTAPI LocalAlloc(UINT uFlags, SIZE_T dwBytes)
HLOCAL NTAPI LocalFree(HLOCAL hMem)
#define memcpy(s1, s2, n)
◆ compat_close()
Closing a file handle can be platform specific. This function takes a file descriptor that is to be closed.
- Parameters
-
[in] | infd | File descriptor to be closed. |
- Returns
- 0 if the file was successfully closed. A return value of -1 indicates an error.
Definition at line 253 of file compat.c.
254{
255#if (defined(WIN32) && !defined (__CYGWIN__))
257#else
259#endif
260}
_Check_return_opt_ _CRTIMP int __cdecl _close(_In_ int _FileHandle)
◆ compat_dirclose()
Definition at line 481 of file compat.c.
482{
484 {
486#ifdef WANT_WIN32_UNICODE
488#else
490#endif
492 }
493}
BOOL WINAPI FindClose(HANDLE hFindFile)
int __cdecl closedir(DIR *)
◆ compat_diropen()
Definition at line 431 of file compat.c.
432{
439#ifdef WANT_WIN32_UNICODE
441 {
443 wchar_t *wpattern;
445 wpattern = u2wlongpath(
pattern);
446 if(wpattern)
447 {
450 {
451
454 }
455 else
457 }
460 }
461#else
464 {
467 }
468#endif
470 {
473 {
476 }
477 }
479}
#define INVALID_HANDLE_VALUE
HANDLE WINAPI FindFirstFileW(IN LPCWSTR lpFileName, OUT LPWIN32_FIND_DATAW lpFindFileData)
DIR *__cdecl opendir(const char *)
◆ compat_fclose()
Definition at line 262 of file compat.c.
263{
265}
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
◆ compat_fdopen()
Also fdopen to avoid having to define POSIX macros in various source files.
Definition at line 248 of file compat.c.
249{
251}
_Check_return_ _CRTIMP FILE *__cdecl fdopen(_In_ int _FileHandle, _In_z_ const char *_Format)
◆ compat_fopen()
Definition at line 218 of file compat.c.
219{
221#ifdef WANT_WIN32_UNICODE
222 int cnt = 0;
223 wchar_t *wname =
NULL;
224 wchar_t *wmode =
NULL;
225
227 if(!wname)
228 goto fopen_fallback;
230 if( (wmode ==
NULL) || (cnt == 0))
231 goto fopen_fallback;
232
235
236fopen_fallback:
237#endif
239#ifdef WANT_WIN32_UNICODE
240
241fopen_ok:
244#endif
246}
_Check_return_ _CRTIMP FILE *__cdecl _wfopen(_In_z_ const wchar_t *_Filename, _In_z_ const wchar_t *_Mode)
_Check_return_ _CRTIMP FILE *__cdecl fopen(_In_z_ const char *_Filename, _In_z_ const char *_Mode)
◆ compat_getenv()
Definition at line 52 of file compat.c.
53{
55#ifdef WANT_WIN32_UNICODE
57 wchar_t *wname =
NULL;
59 {
64 }
65#else
69#endif
71}
static LPCWSTR LPCWSTR LPCWSTR env
_Check_return_ _CRTIMP wchar_t *__cdecl _wgetenv(_In_z_ const wchar_t *_VarName)
_Check_return_ char *__cdecl getenv(_In_z_ const char *_VarName)
◆ compat_isdir()
Definition at line 395 of file compat.c.
396{
398#ifdef WANT_WIN32_UNICODE
399 wchar_t *wpath;
400 wpath = u2wlongpath(
path);
401 if(wpath)
402 {
407 }
408#else
411 {
414 }
415#endif
417}
DWORD WINAPI GetFileAttributesW(LPCWSTR lpFileName)
#define FILE_ATTRIBUTE_DIRECTORY
#define INVALID_FILE_ATTRIBUTES
◆ compat_nextdir()
Definition at line 529 of file compat.c.
530{
533#ifdef WANT_WIN32_UNICODE
535 {
538 {
542 }
543 }
544#else
545 {
548 {
551 if(fullpath && !
stat(fullpath, &fst) &&
S_ISDIR(fst.st_mode))
552 {
555 }
557 }
558 }
559#endif
561}
BOOL WINAPI FindNextFileW(IN HANDLE hFindFile, OUT LPWIN32_FIND_DATAW lpFindFileData)
struct dirent *__cdecl readdir(DIR *)
◆ compat_nextfile()
Definition at line 495 of file compat.c.
496{
499#ifdef WANT_WIN32_UNICODE
501 {
504 {
508 }
509 }
510#else
511 {
514 {
517 if(fullpath && !
stat(fullpath, &fst) &&
S_ISREG(fst.st_mode))
518 {
521 }
523 }
524 }
525#endif
527}
◆ compat_open()
Opening a file handle can be different. This function here is defined to take a path in native encoding (ISO8859 / UTF-8 / ...), or, when MS Windows Unicode support is enabled, an UTF-8 string that will be converted back to native UCS-2 (wide character) before calling the system's open function.
- Parameters
-
[in] | wptr | Pointer to wide string. |
[in] | mbptr | Pointer to multibyte string. |
- Returns
- file descriptor (>=0) or error code.
Definition at line 181 of file compat.c.
182{
184#if defined (WANT_WIN32_UNICODE)
185 wchar_t *frag =
NULL;
186
188
189 if(!frag)
190 goto open_fallback;
191
192
195 goto open_ok;
196
197open_fallback:
198#endif
199
200#if (defined(WIN32) && !defined (__CYGWIN__))
201
202
204#else
206#endif
207
208#if defined (WANT_WIN32_UNICODE)
209open_ok:
211#endif
212
214}
_CRTIMP int __cdecl _wopen(const wchar_t *_Filename, int _OpenFlag,...)
_CRTIMP int __cdecl _open(const char *_Filename, int _OpenFlag,...)
◆ compat_strdup()
◆ safe_realloc()
◆ unintr_fwrite()
◆ unintr_read()
Definition at line 631 of file compat.c.
632{
633 size_t got = 0;
635 {
638 break;
640 got += part;
641 }
642 return got;
643}
static unsigned char bytes[4]
◆ unintr_write()
Definition at line 616 of file compat.c.
617{
618 size_t written = 0;
620 {
623 break;
625 written += part;
626 }
627 return written;
628}
◆ win32_utf8_wide()
win32_mbc2uni Converts a null terminated UTF-8 string to a UCS-2 equivalent. Caller is supposed to free allocated buffer.
- Parameters
-
[out] | mbptr | Pointer to multibyte string. |
[in] | wptr | Pointer to wide string. |
[out] | buflen | Optional parameter for length of allocated buffer. |
- Returns
- status of WideCharToMultiByte conversion.
MultiByteToWideChar - http://msdn.microsoft.com/en-us/library/dd319072(VS.85).aspx
◆ win32_wide_utf8()
win32_uni2mbc Converts a null terminated UCS-2 string to a multibyte (UTF-8) equivalent. Caller is supposed to free allocated buffer.
- Parameters
-
[in] | wptr | Pointer to wide string. |
[out] | mbptr | Pointer to multibyte string. |
[out] | buflen | Optional parameter for length of allocated buffer. |
- Returns
- status of WideCharToMultiByte conversion.
WideCharToMultiByte - http://msdn.microsoft.com/en-us/library/dd374130(VS.85).aspx
◆ catchsignal