Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "curl_setup.h"
00024
00025 #ifdef NETWARE
00026
00027 #ifdef __NOVELL_LIBC__
00028
00029 #include <library.h>
00030 #include <netware.h>
00031 #include <screen.h>
00032 #include <nks/thread.h>
00033 #include <nks/synch.h>
00034
00035 #include "curl_memory.h"
00036
00037 #include "memdebug.h"
00038
00039 typedef struct
00040 {
00041 int _errno;
00042 void *twentybytes;
00043 } libthreaddata_t;
00044
00045 typedef struct
00046 {
00047 int x;
00048 int y;
00049 int z;
00050 void *tenbytes;
00051 NXKey_t perthreadkey;
00052 NXMutex_t *lock;
00053 } libdata_t;
00054
00055 int gLibId = -1;
00056 void *gLibHandle = (void *) NULL;
00057 rtag_t gAllocTag = (rtag_t) NULL;
00058 NXMutex_t *gLibLock = (NXMutex_t *) NULL;
00059
00060
00061 int DisposeLibraryData(void *);
00062 void DisposeThreadData(void *);
00063 int GetOrSetUpData(int id, libdata_t **data, libthreaddata_t **threaddata);
00064
00065
00066 int _NonAppStart(void *NLMHandle,
00067 void *errorScreen,
00068 const char *cmdLine,
00069 const char *loadDirPath,
00070 size_t uninitializedDataLength,
00071 void *NLMFileHandle,
00072 int (*readRoutineP)(int conn,
00073 void *fileHandle, size_t offset,
00074 size_t nbytes,
00075 size_t *bytesRead,
00076 void *buffer),
00077 size_t customDataOffset,
00078 size_t customDataSize,
00079 int messageCount,
00080 const char **messages)
00081 {
00082 NX_LOCK_INFO_ALLOC(liblock, "Per-Application Data Lock", 0);
00083
00084 #ifndef __GNUC__
00085 #pragma unused(cmdLine)
00086 #pragma unused(loadDirPath)
00087 #pragma unused(uninitializedDataLength)
00088 #pragma unused(NLMFileHandle)
00089 #pragma unused(readRoutineP)
00090 #pragma unused(customDataOffset)
00091 #pragma unused(customDataSize)
00092 #pragma unused(messageCount)
00093 #pragma unused(messages)
00094 #endif
00095
00096
00097
00098
00099
00100
00101
00102 gAllocTag = AllocateResourceTag(NLMHandle,
00103 "<library-name> memory allocations",
00104 AllocSignature);
00105
00106 if(!gAllocTag) {
00107 OutputToScreen(errorScreen, "Unable to allocate resource tag for "
00108 "library memory allocations.\n");
00109 return -1;
00110 }
00111
00112 gLibId = register_library(DisposeLibraryData);
00113
00114 if(gLibId < -1) {
00115 OutputToScreen(errorScreen, "Unable to register library with kernel.\n");
00116 return -1;
00117 }
00118
00119 gLibHandle = NLMHandle;
00120
00121 gLibLock = NXMutexAlloc(0, 0, &liblock);
00122
00123 if(!gLibLock) {
00124 OutputToScreen(errorScreen, "Unable to allocate library data lock.\n");
00125 return -1;
00126 }
00127
00128 return 0;
00129 }
00130
00131
00132
00133
00134
00135 void _NonAppStop(void)
00136 {
00137 (void) unregister_library(gLibId);
00138 NXMutexFree(gLibLock);
00139 }
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152 int _NonAppCheckUnload(void)
00153 {
00154 return 0;
00155 }
00156
00157 int GetOrSetUpData(int id, libdata_t **appData,
00158 libthreaddata_t **threadData)
00159 {
00160 int err;
00161 libdata_t *app_data;
00162 libthreaddata_t *thread_data;
00163 NXKey_t key;
00164 NX_LOCK_INFO_ALLOC(liblock, "Application Data Lock", 0);
00165
00166 err = 0;
00167 thread_data = (libthreaddata_t *) NULL;
00168
00169
00170
00171
00172
00173
00174 app_data = (libdata_t *) get_app_data(id);
00175
00176 if(!app_data) {
00177
00178
00179
00180
00181
00182
00183
00184
00185 NXLock(gLibLock);
00186
00187 app_data = (libdata_t *) get_app_data(id);
00188 if(!app_data) {
00189 app_data = malloc(sizeof(libdata_t));
00190
00191 if(app_data) {
00192 memset(app_data, 0, sizeof(libdata_t));
00193
00194 app_data->tenbytes = malloc(10);
00195 app_data->lock = NXMutexAlloc(0, 0, &liblock);
00196
00197 if(!app_data->tenbytes || !app_data->lock) {
00198 if(app_data->lock)
00199 NXMutexFree(app_data->lock);
00200
00201 free(app_data);
00202 app_data = (libdata_t *) NULL;
00203 err = ENOMEM;
00204 }
00205
00206 if(app_data) {
00207
00208
00209
00210
00211
00212
00213
00214
00215 err = set_app_data(gLibId, app_data);
00216
00217 if(err) {
00218 free(app_data);
00219 app_data = (libdata_t *) NULL;
00220 err = ENOMEM;
00221 }
00222 else {
00223
00224 err = NXKeyCreate(DisposeThreadData, (void *) NULL, &key);
00225
00226 if(err)
00227 key = -1;
00228
00229 app_data->perthreadkey = key;
00230 }
00231 }
00232 }
00233 }
00234
00235 NXUnlock(gLibLock);
00236 }
00237
00238 if(app_data) {
00239 key = app_data->perthreadkey;
00240
00241 if(key != -1
00242 && !(err = NXKeyGetValue(key, (void **) &thread_data))
00243 && !thread_data) {
00244
00245
00246
00247
00248
00249
00250
00251 thread_data = malloc(sizeof(libthreaddata_t));
00252
00253 if(thread_data) {
00254 thread_data->_errno = 0;
00255 thread_data->twentybytes = malloc(20);
00256
00257 if(!thread_data->twentybytes) {
00258 free(thread_data);
00259 thread_data = (libthreaddata_t *) NULL;
00260 err = ENOMEM;
00261 }
00262
00263 err = NXKeySetValue(key, thread_data);
00264 if(err) {
00265 free(thread_data->twentybytes);
00266 free(thread_data);
00267 thread_data = (libthreaddata_t *) NULL;
00268 }
00269 }
00270 }
00271 }
00272
00273 if(appData)
00274 *appData = app_data;
00275
00276 if(threadData)
00277 *threadData = thread_data;
00278
00279 return err;
00280 }
00281
00282 int DisposeLibraryData(void *data)
00283 {
00284 if(data) {
00285 void *tenbytes = ((libdata_t *) data)->tenbytes;
00286
00287 free(tenbytes);
00288 free(data);
00289 }
00290
00291 return 0;
00292 }
00293
00294 void DisposeThreadData(void *data)
00295 {
00296 if(data) {
00297 void *twentybytes = ((libthreaddata_t *) data)->twentybytes;
00298
00299 free(twentybytes);
00300 free(data);
00301 }
00302 }
00303
00304 #else
00305
00306 #include <nwthread.h>
00307
00308 int main(void)
00309 {
00310
00311
00312
00313
00314
00315 ExitThread(TSR_THREAD, 0);
00316 return 0;
00317 }
00318
00319 #endif
00320
00321 #else
00322
00323 #ifdef __POCC__
00324 # pragma warn(disable:2024)
00325 #endif
00326
00327 #endif