Changeset 3942
- Timestamp:
- Dec 26, 2014, 8:15:42 PM (11 years ago)
- Location:
- trunk/libc
- Files:
-
- 5 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/libc/include/os2safe.h
r3926 r3942 1 1 /* os2safe.h,v 1.1 2003/10/06 00:54:20 bird Exp */ 2 2 /** @file 3 *4 3 * OS/2 API High Memory Wrappers. 5 4 * You include this file before os2.h and link with -los2safe. 5 */ 6 7 /* 6 8 * 7 * Copyright (c) 2003-201 4knut st. osmundsen <bird-srcspam@anduin.net>9 * Copyright (c) 2003-2015 knut st. osmundsen <bird-srcspam@anduin.net> 8 10 * 9 11 * … … 44 46 #define DosStartSession SafeDosStartSession 45 47 #define DosQueryAppType SafeDosQueryAppType 46 #define DosDevIOCtl SafeDosDevIOCtl 48 49 #define DosMapCase SafeDosMapCase 50 #define DosQueryCollate SafeDosQueryCollate 51 #define DosQueryCp SafeDosQueryCp 52 #define DosQueryCtryInfo SafeDosQueryCtryInfo 53 #define DosQueryDBCSEnv SafeDosQueryDBCSEnv 54 47 55 #define WinUpper SafeWinUpper 48 56 49 57 #endif 58 -
trunk/libc/src/libos2/safe/SafeDosForceDelete.c
r3897 r3942 34 34 rc = DosForceDelete(SAFE_PCSZ_USE(pszFileName)); 35 35 SAFE_PCSZ_DONE(pszFileName); 36 SAFE_DOS_FAILURE();37 36 return rc; 38 37 } -
trunk/libc/src/libos2/safe/SafeDosOpen.c
r3926 r3942 50 50 51 51 SAFE_PCSZ_DONE(pszFileName); 52 SAFE_DOS_FAILURE();53 52 return rc; 54 53 } -
trunk/libc/src/libos2/safe/SafeDosOpenL.c
r3897 r3942 62 62 63 63 SAFE_PCSZ_DONE(pszFileName); 64 SAFE_DOS_FAILURE();65 64 return rc; 66 65 } -
trunk/libc/src/libos2/safe/SafeDosQueryAppType.c
r3897 r3942 48 48 49 49 SAFE_PCSZ_DONE(pszName); 50 SAFE_DOS_FAILURE();51 50 return rc; 52 51 } -
trunk/libc/src/libos2/safe/SafeDosWaitNPipe.c
r3897 r3942 34 34 rc = DosWaitNPipe(SAFE_PCSZ_USE(pszName), ulTimeout); 35 35 SAFE_PCSZ_DONE(pszName); 36 SAFE_DOS_FAILURE();37 36 return rc; 38 37 } 38 -
trunk/libc/src/libos2/safe/safe.h
r3897 r3942 37 37 /** Wrap a const string. */ 38 38 #define SAFE_PCSZ(arg) \ 39 char * arg##_safe = (char*)arg; \ 40 if (SAFE_IS_HIGH(arg)) \ 41 { \ 42 int cch = strlen(arg) + 1; \ 43 arg##_safe = _lmalloc(cch); \ 44 if (!arg##_safe) goto safe_failure; \ 45 memcpy(arg##_safe, (arg), cch); \ 46 } \ 47 { 48 39 { \ 40 char *arg##_safe = (char *)arg; \ 41 if (SAFE_IS_HIGH(arg)) \ 42 { \ 43 int cch = strlen(arg) + 1; \ 44 arg##_safe = _lmalloc(cch); \ 45 if (!arg##_safe) { rc = 8; goto l_##arg##_failed; } \ 46 memcpy(arg##_safe, (arg), cch); \ 47 } else do {} while (0) 49 48 50 49 /** Use the const string. */ … … 53 52 /** Cleanup a const string. */ 54 53 #define SAFE_PCSZ_DONE(arg) \ 55 } \ 56 if (arg##_safe != (char*)arg) free(arg##_safe) 54 if (arg##_safe != (char *)arg) \ 55 free(arg##_safe); \ 56 } \ 57 l_##arg##_failed: do {} while (0) 58 59 /** Wrap an input/output buffer. */ 60 #define SAFE_INOUTBUF(arg, len, type) \ 61 { \ 62 type *arg##_safe = arg; \ 63 if (SAFE_IS_HIGH(arg)) \ 64 { \ 65 arg##_safe = (type *)_lmalloc(len); \ 66 if (!arg##_safe) { rc = 8; goto l_##arg##_failed; } \ 67 memcpy(arg##_safe, (arg), len);\ 68 } else do {} while (0) 69 70 /** Use the safe input/output buffer. */ 71 #define SAFE_INOUTBUF_USE(arg) arg##_safe 72 73 /** Cleanup an input/output buffer. */ 74 #define SAFE_INOUTBUF_DONE(arg, len) \ 75 if (arg##_safe != arg) \ 76 { \ 77 memcpy(arg, arg##_safe, len); \ 78 free(arg##_safe); \ 79 } \ 80 } \ 81 l_##arg##_failed: do {} while (0) 82 83 /** Wrap the pointer to an input only type/struct. */ 84 #define SAFE_INTYPE(arg, type) \ 85 { \ 86 type *arg##_free = NULL; \ 87 type *arg##_safe = (type *)arg; \ 88 if (SAFE_IS_HIGH(arg)) \ 89 { \ 90 if (sizeof(type) < 256) \ 91 arg##_safe = (type *)alloca(sizeof(type)); \ 92 else \ 93 arg##_free = arg##_safe = (type *)_lmalloc(sizeof(type)); \ 94 if (!arg##_safe) { rc = 8; goto l_##arg##_failed; } \ 95 *arg##_safe = *(arg); \ 96 } else do {} while (0) 97 98 /** Use the safe pointer to an input only type/struct. */ 99 #define SAFE_INTYPE_USE(arg) arg##_safe 100 101 /** Cleanup after wrapping an input only type/struct. */ 102 #define SAFE_INTYPE_DONE(arg) \ 103 if (arg##_free) \ 104 free(arg##_free); \ 105 } \ 106 l_##arg##_failed: do {} while (0) 107 108 /** Wrap the pointer to an input/output type/struct. */ 109 #define SAFE_INOUTTYPE(arg, type) \ 110 { \ 111 type *arg##_free = NULL; \ 112 type *arg##_safe = (type *)arg; \ 113 if (SAFE_IS_HIGH(arg)) \ 114 { \ 115 if (sizeof(type) < 256) \ 116 arg##_safe = (type *)alloca(sizeof(type)); \ 117 else \ 118 arg##_free = arg##_safe = (type *)_lmalloc(sizeof(type)); \ 119 if (!arg##_safe) { rc = 8; goto l_##arg##_failed; } \ 120 *arg##_safe = *(arg); \ 121 } else do {} while (0) 122 123 /** Use the safe pointer to an input/output type/struct. */ 124 #define SAFE_INOUTTYPE_USE(arg) arg##_safe 125 126 /** Cleanup after wrapping an input/output type/struct. */ 127 #define SAFE_INOUTTYPE_DONE(arg) \ 128 if (arg##_safe != (arg)) \ 129 *(arg) = *arg##_safe; \ 130 if (arg##_free) \ 131 free(arg##_free); \ 132 } \ 133 l_##arg##_failed: do {} while (0) 134 57 135 58 136 59 137 /** Generic failure label for Dos API wappers. 60 * It'll just return out of memory error. */ 61 #define SAFE_DOS_FAILURE() \ 62 if (0) \ 63 { \ 64 safe_failure: \ 65 rc = 8; \ 66 } 138 * It'll just return out of memory error. 139 * @obsolete */ 140 #define SAFE_DOS_FAILURE() do { } while (0) 67 141 68 142
Note:
See TracChangeset
for help on using the changeset viewer.