123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325 |
- #include "curl_setup.h"
- #ifdef NETWARE
- #ifdef __NOVELL_LIBC__
- #include <library.h>
- #include <netware.h>
- #include <screen.h>
- #include <nks/thread.h>
- #include <nks/synch.h>
- #include "curl_memory.h"
- #include "memdebug.h"
- typedef struct
- {
- int _errno;
- void *twentybytes;
- } libthreaddata_t;
- typedef struct
- {
- int x;
- int y;
- int z;
- void *tenbytes;
- NXKey_t perthreadkey;
- NXMutex_t *lock;
- } libdata_t;
- int gLibId = -1;
- void *gLibHandle = (void *) NULL;
- rtag_t gAllocTag = (rtag_t) NULL;
- NXMutex_t *gLibLock = (NXMutex_t *) NULL;
- int DisposeLibraryData(void *);
- void DisposeThreadData(void *);
- int GetOrSetUpData(int id, libdata_t **data, libthreaddata_t **threaddata);
- int _NonAppStart(void *NLMHandle,
- void *errorScreen,
- const char *cmdLine,
- const char *loadDirPath,
- size_t uninitializedDataLength,
- void *NLMFileHandle,
- int (*readRoutineP)(int conn,
- void *fileHandle, size_t offset,
- size_t nbytes,
- size_t *bytesRead,
- void *buffer),
- size_t customDataOffset,
- size_t customDataSize,
- int messageCount,
- const char **messages)
- {
- NX_LOCK_INFO_ALLOC(liblock, "Per-Application Data Lock", 0);
- #ifndef __GNUC__
- #pragma unused(cmdLine)
- #pragma unused(loadDirPath)
- #pragma unused(uninitializedDataLength)
- #pragma unused(NLMFileHandle)
- #pragma unused(readRoutineP)
- #pragma unused(customDataOffset)
- #pragma unused(customDataSize)
- #pragma unused(messageCount)
- #pragma unused(messages)
- #endif
-
- gAllocTag = AllocateResourceTag(NLMHandle,
- "<library-name> memory allocations",
- AllocSignature);
- if(!gAllocTag) {
- OutputToScreen(errorScreen, "Unable to allocate resource tag for "
- "library memory allocations.\n");
- return -1;
- }
- gLibId = register_library(DisposeLibraryData);
- if(gLibId < -1) {
- OutputToScreen(errorScreen, "Unable to register library with kernel.\n");
- return -1;
- }
- gLibHandle = NLMHandle;
- gLibLock = NXMutexAlloc(0, 0, &liblock);
- if(!gLibLock) {
- OutputToScreen(errorScreen, "Unable to allocate library data lock.\n");
- return -1;
- }
- return 0;
- }
- void _NonAppStop(void)
- {
- (void) unregister_library(gLibId);
- NXMutexFree(gLibLock);
- }
- int _NonAppCheckUnload(void)
- {
- return 0;
- }
- int GetOrSetUpData(int id, libdata_t **appData,
- libthreaddata_t **threadData)
- {
- int err;
- libdata_t *app_data;
- libthreaddata_t *thread_data;
- NXKey_t key;
- NX_LOCK_INFO_ALLOC(liblock, "Application Data Lock", 0);
- err = 0;
- thread_data = (libthreaddata_t *) NULL;
-
- app_data = (libdata_t *) get_app_data(id);
- if(!app_data) {
-
- NXLock(gLibLock);
- app_data = (libdata_t *) get_app_data(id);
- if(!app_data) {
- app_data = calloc(1, sizeof(libdata_t));
- if(app_data) {
- app_data->tenbytes = malloc(10);
- app_data->lock = NXMutexAlloc(0, 0, &liblock);
- if(!app_data->tenbytes || !app_data->lock) {
- if(app_data->lock)
- NXMutexFree(app_data->lock);
- free(app_data);
- app_data = (libdata_t *) NULL;
- err = ENOMEM;
- }
- if(app_data) {
-
- err = set_app_data(gLibId, app_data);
- if(err) {
- free(app_data);
- app_data = (libdata_t *) NULL;
- err = ENOMEM;
- }
- else {
-
- err = NXKeyCreate(DisposeThreadData, (void *) NULL, &key);
- if(err)
- key = -1;
- app_data->perthreadkey = key;
- }
- }
- }
- }
- NXUnlock(gLibLock);
- }
- if(app_data) {
- key = app_data->perthreadkey;
- if(key != -1
- && !(err = NXKeyGetValue(key, (void **) &thread_data))
- && !thread_data) {
-
- thread_data = malloc(sizeof(libthreaddata_t));
- if(thread_data) {
- thread_data->_errno = 0;
- thread_data->twentybytes = malloc(20);
- if(!thread_data->twentybytes) {
- free(thread_data);
- thread_data = (libthreaddata_t *) NULL;
- err = ENOMEM;
- }
- err = NXKeySetValue(key, thread_data);
- if(err) {
- free(thread_data->twentybytes);
- free(thread_data);
- thread_data = (libthreaddata_t *) NULL;
- }
- }
- }
- }
- if(appData)
- *appData = app_data;
- if(threadData)
- *threadData = thread_data;
- return err;
- }
- int DisposeLibraryData(void *data)
- {
- if(data) {
- void *tenbytes = ((libdata_t *) data)->tenbytes;
- free(tenbytes);
- free(data);
- }
- return 0;
- }
- void DisposeThreadData(void *data)
- {
- if(data) {
- void *twentybytes = ((libthreaddata_t *) data)->twentybytes;
- free(twentybytes);
- free(data);
- }
- }
- #else
- #include <nwthread.h>
- int main(void)
- {
-
-
- ExitThread(TSR_THREAD, 0);
- return 0;
- }
- #endif
- #else
- #ifdef __POCC__
- # pragma warn(disable:2024)
- #endif
- #endif
|