From 5b55f9ecb34a00af236b2275ffa9adab492a93b6 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 17 Mar 2004 12:46:42 +0000 Subject: =?UTF-8?q?G=FCnter=20Knauf's=20NetWare=20changes.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/nwlib.c | 329 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 329 insertions(+) create mode 100644 lib/nwlib.c (limited to 'lib/nwlib.c') diff --git a/lib/nwlib.c b/lib/nwlib.c new file mode 100644 index 000000000..410a6311b --- /dev/null +++ b/lib/nwlib.c @@ -0,0 +1,329 @@ +/*************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) 1998 - 2004, Daniel Stenberg, , et al. + * + * This software is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at http://curl.haxx.se/docs/copyright.html. + * + * You may opt to use, copy, modify, merge, publish, distribute and/or sell + * copies of the Software, and permit persons to whom the Software is + * furnished to do so, under the terms of the COPYING file. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + * $Id$ + ***************************************************************************/ + +/* This file is only used in the NetWare build */ + +#include +#include +#include +#include +#include +#include +#include +#include + + +typedef struct +{ + int _errno; + void *twentybytes; +} libthreaddata_t; + +typedef struct +{ + int x; + int y; + int z; + void *tenbytes; + NXKey_t perthreadkey; // if -1, no key obtained... + NXMutex_t *lock; +} libdata_t; + +int gLibId = -1; +void *gLibHandle = (void *) NULL; +rtag_t gAllocTag = (rtag_t) NULL; +NXMutex_t *gLibLock = (NXMutex_t *) NULL; + + + +// internal library function prototypes... +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 + +/* +** Here we process our command line, post errors (to the error screen), +** perform initializations and anything else we need to do before being able +** to accept calls into us. If we succeed, we return non-zero and the NetWare +** Loader will leave us up, otherwise we fail to load and get dumped. +*/ + gAllocTag = AllocateResourceTag(NLMHandle, + " 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 ) +{ +/* +** Here we clean up any resources we allocated. Resource tags is a big part +** of what we created, but NetWare doesn't ask us to free those. +*/ + (void) unregister_library(gLibId); + NXMutexFree(gLibLock); +} + +int _NonAppCheckUnload( void ) +{ +/* +** This function cannot be the first in the file for if the file is linked +** first, then the check-unload function's offset will be nlmname.nlm+0 +** which is how to tell that there isn't one. When the check function is +** first in the linked objects, it is ambiguous. For this reason, we will +** put it inside this file after the stop function. +** +** Here we check to see if it's alright to ourselves to be unloaded. If not, +** we return a non-zero value. Right now, there isn't any reason not to allow +** it. +*/ + 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; +// NXMutex_t *lock; + NX_LOCK_INFO_ALLOC(liblock, "Application Data Lock", 0); + + err = 0; + thread_data = (libthreaddata_t *) NULL; + +/* +** Attempt to get our data for the application calling us. This is where we +** store whatever application-specific information we need to carry in support +** of calling applications. +*/ + app_data = (libdata_t *) get_app_data(id); + + if (!app_data) + { +/* +** This application hasn't called us before; set up application AND per-thread +** data. Of course, just in case a thread from this same application is calling +** us simultaneously, we better lock our application data-creation mutex. We +** also need to recheck for data after we acquire the lock because WE might be +** that other thread that was too late to create the data and the first thread +** in will have created it. +*/ + NXLock(gLibLock); + + if (!(app_data = (libdata_t *) get_app_data(id))) + { + app_data = (libdata_t *) malloc(sizeof(libdata_t)); + + if (app_data) + { + memset(app_data, 0, sizeof(libdata_t)); + + 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) + { +/* +** Here we burn in the application data that we were trying to get by calling +** get_app_data(). Next time we call the first function, we'll get this data +** we're just now setting. We also go on here to establish the per-thread data +** for the calling thread, something we'll have to do on each application +** thread the first time it calls us. +*/ + err = set_app_data(gLibId, app_data); + + if (err) + { + free(app_data); + app_data = (libdata_t *) NULL; + err = ENOMEM; + } + else + { + // create key for thread-specific data... + err = NXKeyCreate(DisposeThreadData, (void *) NULL, &key); + + if (err) // (no more keys left?) + key = -1; + + app_data->perthreadkey = key; + } + } + } + } + + NXUnlock(gLibLock); + } + + if (app_data) + { + key = app_data->perthreadkey; + + if ( key != -1 // couldn't create a key? no thread data + && !(err = NXKeyGetValue(key, (void **) &thread_data)) + && !thread_data) + { +/* +** Allocate the per-thread data for the calling thread. Regardless of whether +** there was already application data or not, this may be the first call by a +** a new thread. The fact that we allocation 20 bytes on a pointer is not very +** important, this just helps to demonstrate that we can have arbitrarily +** complex per-thread data. +*/ + thread_data = (libthreaddata_t *) 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; + } + + if ((err = NXKeySetValue(key, thread_data))) + { + 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; + + if (tenbytes) + free(tenbytes); + + free(data); + } + + return 0; +} + +void DisposeThreadData +( + void *data +) +{ + if (data) + { + void *twentybytes = ((libthreaddata_t *) data)->twentybytes; + + if (twentybytes) + free(twentybytes); + + free(data); + } +} -- cgit v1.2.1 From ffb35ff5c397daae8e6681563f75dbb4e58bda00 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 17 Mar 2004 13:36:45 +0000 Subject: =?UTF-8?q?G=FCnter=20Knauf's=20update,=20mainly=20converted=20to?= =?UTF-8?q?=20plain=20old=20C=20comments.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/nwlib.c | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) (limited to 'lib/nwlib.c') diff --git a/lib/nwlib.c b/lib/nwlib.c index 410a6311b..d54f4ac96 100644 --- a/lib/nwlib.c +++ b/lib/nwlib.c @@ -21,8 +21,6 @@ * $Id$ ***************************************************************************/ -/* This file is only used in the NetWare build */ - #include #include #include @@ -45,7 +43,7 @@ typedef struct int y; int z; void *tenbytes; - NXKey_t perthreadkey; // if -1, no key obtained... + NXKey_t perthreadkey; /* if -1, no key obtained... */ NXMutex_t *lock; } libdata_t; @@ -54,9 +52,7 @@ void *gLibHandle = (void *) NULL; rtag_t gAllocTag = (rtag_t) NULL; NXMutex_t *gLibLock = (NXMutex_t *) NULL; - - -// internal library function prototypes... +/* internal library function prototypes... */ int DisposeLibraryData ( void * ); void DisposeThreadData ( void * ); int GetOrSetUpData ( int id, libdata_t **data, libthreaddata_t **threaddata ); @@ -129,18 +125,16 @@ int _NonAppStart return 0; } -void _NonAppStop( void ) -{ /* ** Here we clean up any resources we allocated. Resource tags is a big part ** of what we created, but NetWare doesn't ask us to free those. */ +void _NonAppStop( void ) +{ (void) unregister_library(gLibId); NXMutexFree(gLibLock); } -int _NonAppCheckUnload( void ) -{ /* ** This function cannot be the first in the file for if the file is linked ** first, then the check-unload function's offset will be nlmname.nlm+0 @@ -152,6 +146,8 @@ int _NonAppCheckUnload( void ) ** we return a non-zero value. Right now, there isn't any reason not to allow ** it. */ +int _NonAppCheckUnload( void ) +{ return 0; } @@ -166,7 +162,6 @@ int GetOrSetUpData libdata_t *app_data; libthreaddata_t *thread_data; NXKey_t key; -// NXMutex_t *lock; NX_LOCK_INFO_ALLOC(liblock, "Application Data Lock", 0); err = 0; @@ -231,10 +226,10 @@ int GetOrSetUpData } else { - // create key for thread-specific data... + /* create key for thread-specific data... */ err = NXKeyCreate(DisposeThreadData, (void *) NULL, &key); - if (err) // (no more keys left?) + if (err) /* (no more keys left?) */ key = -1; app_data->perthreadkey = key; @@ -250,7 +245,7 @@ int GetOrSetUpData { key = app_data->perthreadkey; - if ( key != -1 // couldn't create a key? no thread data + if ( key != -1 /* couldn't create a key? no thread data */ && !(err = NXKeyGetValue(key, (void **) &thread_data)) && !thread_data) { @@ -327,3 +322,5 @@ void DisposeThreadData free(data); } } + + -- cgit v1.2.1 From bbafb2eb27954c34967f91c705e74cc0c186970d Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 11 May 2004 11:30:23 +0000 Subject: curl_global_init_mem() allows the memory functions to be replaced. memory.h is included everywhere for this. --- lib/nwlib.c | 330 ++++++++++++++++++++++++++++-------------------------------- 1 file changed, 152 insertions(+), 178 deletions(-) (limited to 'lib/nwlib.c') diff --git a/lib/nwlib.c b/lib/nwlib.c index d54f4ac96..2dd0f4fa5 100644 --- a/lib/nwlib.c +++ b/lib/nwlib.c @@ -30,21 +30,23 @@ #include #include +#include "memory.h" +#include "memdebug.h" typedef struct { - int _errno; - void *twentybytes; + int _errno; + void *twentybytes; } libthreaddata_t; typedef struct { - int x; - int y; - int z; - void *tenbytes; - NXKey_t perthreadkey; /* if -1, no key obtained... */ - NXMutex_t *lock; + int x; + int y; + int z; + void *tenbytes; + NXKey_t perthreadkey; /* if -1, no key obtained... */ + NXMutex_t *lock; } libdata_t; int gLibId = -1; @@ -58,24 +60,24 @@ 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 -) +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); - + NX_LOCK_INFO_ALLOC(liblock, "Per-Application Data Lock", 0); + #ifndef __GNUC__ #pragma unused(cmdLine) #pragma unused(loadDirPath) @@ -94,35 +96,33 @@ int _NonAppStart ** to accept calls into us. If we succeed, we return non-zero and the NetWare ** Loader will leave us up, otherwise we fail to load and get dumped. */ - gAllocTag = AllocateResourceTag(NLMHandle, - " memory allocations", AllocSignature); + gAllocTag = AllocateResourceTag(NLMHandle, + " memory allocations", + AllocSignature); - if (!gAllocTag) - { - OutputToScreen(errorScreen, "Unable to allocate resource tag for " - "library memory allocations.\n"); - return -1; - } + if (!gAllocTag) { + OutputToScreen(errorScreen, "Unable to allocate resource tag for " + "library memory allocations.\n"); + return -1; + } - gLibId = register_library(DisposeLibraryData); + gLibId = register_library(DisposeLibraryData); - if (gLibId < -1) - { - OutputToScreen(errorScreen, "Unable to register library with kernel.\n"); - return -1; - } + if (gLibId < -1) { + OutputToScreen(errorScreen, "Unable to register library with kernel.\n"); + return -1; + } - gLibHandle = NLMHandle; + gLibHandle = NLMHandle; - gLibLock = NXMutexAlloc(0, 0, &liblock); - - if (!gLibLock) - { - OutputToScreen(errorScreen, "Unable to allocate library data lock.\n"); - return -1; - } + gLibLock = NXMutexAlloc(0, 0, &liblock); + + if (!gLibLock) { + OutputToScreen(errorScreen, "Unable to allocate library data lock.\n"); + return -1; + } - return 0; + return 0; } /* @@ -131,8 +131,8 @@ int _NonAppStart */ void _NonAppStop( void ) { - (void) unregister_library(gLibId); - NXMutexFree(gLibLock); + (void) unregister_library(gLibId); + NXMutexFree(gLibLock); } /* @@ -151,31 +151,26 @@ int _NonAppCheckUnload( void ) return 0; } -int GetOrSetUpData -( - int id, - libdata_t **appData, - libthreaddata_t **threadData -) +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); + 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; + err = 0; + thread_data = (libthreaddata_t *) NULL; /* ** Attempt to get our data for the application calling us. This is where we ** store whatever application-specific information we need to carry in support ** of calling applications. */ - app_data = (libdata_t *) get_app_data(id); + app_data = (libdata_t *) get_app_data(id); - if (!app_data) - { + if (!app_data) { /* ** This application hasn't called us before; set up application AND per-thread ** data. Of course, just in case a thread from this same application is calling @@ -184,31 +179,27 @@ int GetOrSetUpData ** that other thread that was too late to create the data and the first thread ** in will have created it. */ - NXLock(gLibLock); - - if (!(app_data = (libdata_t *) get_app_data(id))) - { - app_data = (libdata_t *) malloc(sizeof(libdata_t)); - - if (app_data) - { - memset(app_data, 0, sizeof(libdata_t)); - - 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) - { + NXLock(gLibLock); + + if (!(app_data = (libdata_t *) get_app_data(id))) { + app_data = (libdata_t *) malloc(sizeof(libdata_t)); + + if (app_data) { + memset(app_data, 0, sizeof(libdata_t)); + + 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) { /* ** Here we burn in the application data that we were trying to get by calling ** get_app_data(). Next time we call the first function, we'll get this data @@ -216,39 +207,35 @@ int GetOrSetUpData ** for the calling thread, something we'll have to do on each application ** thread the first time it calls us. */ - err = set_app_data(gLibId, app_data); - - if (err) - { - free(app_data); - app_data = (libdata_t *) NULL; - err = ENOMEM; - } - else - { - /* create key for thread-specific data... */ - err = NXKeyCreate(DisposeThreadData, (void *) NULL, &key); - - if (err) /* (no more keys left?) */ - key = -1; - - app_data->perthreadkey = key; - } - } - } + err = set_app_data(gLibId, app_data); + + if (err) { + free(app_data); + app_data = (libdata_t *) NULL; + err = ENOMEM; + } + else { + /* create key for thread-specific data... */ + err = NXKeyCreate(DisposeThreadData, (void *) NULL, &key); + + if (err) /* (no more keys left?) */ + key = -1; + + app_data->perthreadkey = key; + } } - - NXUnlock(gLibLock); + } } - - if (app_data) - { - key = app_data->perthreadkey; - - if ( key != -1 /* couldn't create a key? no thread data */ - && !(err = NXKeyGetValue(key, (void **) &thread_data)) - && !thread_data) - { + + NXUnlock(gLibLock); + } + + if (app_data) { + key = app_data->perthreadkey; + + if (key != -1 /* couldn't create a key? no thread data */ + && !(err = NXKeyGetValue(key, (void **) &thread_data)) + && !thread_data) { /* ** Allocate the per-thread data for the calling thread. Regardless of whether ** there was already application data or not, this may be the first call by a @@ -256,71 +243,58 @@ int GetOrSetUpData ** important, this just helps to demonstrate that we can have arbitrarily ** complex per-thread data. */ - thread_data = (libthreaddata_t *) 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; - } - - if ((err = NXKeySetValue(key, thread_data))) - { - free(thread_data->twentybytes); - free(thread_data); - thread_data = (libthreaddata_t *) NULL; - } - } + thread_data = (libthreaddata_t *) 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; + } + + if ((err = NXKeySetValue(key, thread_data))) { + free(thread_data->twentybytes); + free(thread_data); + thread_data = (libthreaddata_t *) NULL; } + } } + } - if (appData) - *appData = app_data; + if (appData) + *appData = app_data; - if (threadData) - *threadData = thread_data; + if (threadData) + *threadData = thread_data; - return err; + return err; } -int DisposeLibraryData -( - void *data -) +int DisposeLibraryData( void *data) { - if (data) - { - void *tenbytes = ((libdata_t *) data)->tenbytes; - - if (tenbytes) - free(tenbytes); - - free(data); - } - - return 0; + if (data) { + void *tenbytes = ((libdata_t *) data)->tenbytes; + + if (tenbytes) + free(tenbytes); + + free(data); + } + + return 0; } -void DisposeThreadData -( - void *data -) +void DisposeThreadData(void *data) { - if (data) - { - void *twentybytes = ((libthreaddata_t *) data)->twentybytes; - - if (twentybytes) - free(twentybytes); - - free(data); - } + if (data) { + void *twentybytes = ((libthreaddata_t *) data)->twentybytes; + + if (twentybytes) + free(twentybytes); + + free(data); + } } - - -- cgit v1.2.1 From ef1aa4e5e9ac79dfc06a072ddab7f98b3c498b53 Mon Sep 17 00:00:00 2001 From: Gunter Knauf Date: Thu, 10 Jun 2004 21:20:15 +0000 Subject: converted to UNIX format. --- lib/nwlib.c | 600 ++++++++++++++++++++++++++++++------------------------------ 1 file changed, 300 insertions(+), 300 deletions(-) (limited to 'lib/nwlib.c') diff --git a/lib/nwlib.c b/lib/nwlib.c index 2dd0f4fa5..b0eea56c7 100644 --- a/lib/nwlib.c +++ b/lib/nwlib.c @@ -1,300 +1,300 @@ -/*************************************************************************** - * _ _ ____ _ - * Project ___| | | | _ \| | - * / __| | | | |_) | | - * | (__| |_| | _ <| |___ - * \___|\___/|_| \_\_____| - * - * Copyright (C) 1998 - 2004, Daniel Stenberg, , et al. - * - * This software is licensed as described in the file COPYING, which - * you should have received as part of this distribution. The terms - * are also available at http://curl.haxx.se/docs/copyright.html. - * - * You may opt to use, copy, modify, merge, publish, distribute and/or sell - * copies of the Software, and permit persons to whom the Software is - * furnished to do so, under the terms of the COPYING file. - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY - * KIND, either express or implied. - * - * $Id$ - ***************************************************************************/ - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "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; /* if -1, no key obtained... */ - NXMutex_t *lock; -} libdata_t; - -int gLibId = -1; -void *gLibHandle = (void *) NULL; -rtag_t gAllocTag = (rtag_t) NULL; -NXMutex_t *gLibLock = (NXMutex_t *) NULL; - -/* internal library function prototypes... */ -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 - -/* -** Here we process our command line, post errors (to the error screen), -** perform initializations and anything else we need to do before being able -** to accept calls into us. If we succeed, we return non-zero and the NetWare -** Loader will leave us up, otherwise we fail to load and get dumped. -*/ - gAllocTag = AllocateResourceTag(NLMHandle, - " 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; -} - -/* -** Here we clean up any resources we allocated. Resource tags is a big part -** of what we created, but NetWare doesn't ask us to free those. -*/ -void _NonAppStop( void ) -{ - (void) unregister_library(gLibId); - NXMutexFree(gLibLock); -} - -/* -** This function cannot be the first in the file for if the file is linked -** first, then the check-unload function's offset will be nlmname.nlm+0 -** which is how to tell that there isn't one. When the check function is -** first in the linked objects, it is ambiguous. For this reason, we will -** put it inside this file after the stop function. -** -** Here we check to see if it's alright to ourselves to be unloaded. If not, -** we return a non-zero value. Right now, there isn't any reason not to allow -** it. -*/ -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; - -/* -** Attempt to get our data for the application calling us. This is where we -** store whatever application-specific information we need to carry in support -** of calling applications. -*/ - app_data = (libdata_t *) get_app_data(id); - - if (!app_data) { -/* -** This application hasn't called us before; set up application AND per-thread -** data. Of course, just in case a thread from this same application is calling -** us simultaneously, we better lock our application data-creation mutex. We -** also need to recheck for data after we acquire the lock because WE might be -** that other thread that was too late to create the data and the first thread -** in will have created it. -*/ - NXLock(gLibLock); - - if (!(app_data = (libdata_t *) get_app_data(id))) { - app_data = (libdata_t *) malloc(sizeof(libdata_t)); - - if (app_data) { - memset(app_data, 0, sizeof(libdata_t)); - - 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) { -/* -** Here we burn in the application data that we were trying to get by calling -** get_app_data(). Next time we call the first function, we'll get this data -** we're just now setting. We also go on here to establish the per-thread data -** for the calling thread, something we'll have to do on each application -** thread the first time it calls us. -*/ - err = set_app_data(gLibId, app_data); - - if (err) { - free(app_data); - app_data = (libdata_t *) NULL; - err = ENOMEM; - } - else { - /* create key for thread-specific data... */ - err = NXKeyCreate(DisposeThreadData, (void *) NULL, &key); - - if (err) /* (no more keys left?) */ - key = -1; - - app_data->perthreadkey = key; - } - } - } - } - - NXUnlock(gLibLock); - } - - if (app_data) { - key = app_data->perthreadkey; - - if (key != -1 /* couldn't create a key? no thread data */ - && !(err = NXKeyGetValue(key, (void **) &thread_data)) - && !thread_data) { -/* -** Allocate the per-thread data for the calling thread. Regardless of whether -** there was already application data or not, this may be the first call by a -** a new thread. The fact that we allocation 20 bytes on a pointer is not very -** important, this just helps to demonstrate that we can have arbitrarily -** complex per-thread data. -*/ - thread_data = (libthreaddata_t *) 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; - } - - if ((err = NXKeySetValue(key, thread_data))) { - 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; - - if (tenbytes) - free(tenbytes); - - free(data); - } - - return 0; -} - -void DisposeThreadData(void *data) -{ - if (data) { - void *twentybytes = ((libthreaddata_t *) data)->twentybytes; - - if (twentybytes) - free(twentybytes); - - free(data); - } -} +/*************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) 1998 - 2004, Daniel Stenberg, , et al. + * + * This software is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at http://curl.haxx.se/docs/copyright.html. + * + * You may opt to use, copy, modify, merge, publish, distribute and/or sell + * copies of the Software, and permit persons to whom the Software is + * furnished to do so, under the terms of the COPYING file. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + * $Id$ + ***************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "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; /* if -1, no key obtained... */ + NXMutex_t *lock; +} libdata_t; + +int gLibId = -1; +void *gLibHandle = (void *) NULL; +rtag_t gAllocTag = (rtag_t) NULL; +NXMutex_t *gLibLock = (NXMutex_t *) NULL; + +/* internal library function prototypes... */ +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 + +/* +** Here we process our command line, post errors (to the error screen), +** perform initializations and anything else we need to do before being able +** to accept calls into us. If we succeed, we return non-zero and the NetWare +** Loader will leave us up, otherwise we fail to load and get dumped. +*/ + gAllocTag = AllocateResourceTag(NLMHandle, + " 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; +} + +/* +** Here we clean up any resources we allocated. Resource tags is a big part +** of what we created, but NetWare doesn't ask us to free those. +*/ +void _NonAppStop( void ) +{ + (void) unregister_library(gLibId); + NXMutexFree(gLibLock); +} + +/* +** This function cannot be the first in the file for if the file is linked +** first, then the check-unload function's offset will be nlmname.nlm+0 +** which is how to tell that there isn't one. When the check function is +** first in the linked objects, it is ambiguous. For this reason, we will +** put it inside this file after the stop function. +** +** Here we check to see if it's alright to ourselves to be unloaded. If not, +** we return a non-zero value. Right now, there isn't any reason not to allow +** it. +*/ +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; + +/* +** Attempt to get our data for the application calling us. This is where we +** store whatever application-specific information we need to carry in support +** of calling applications. +*/ + app_data = (libdata_t *) get_app_data(id); + + if (!app_data) { +/* +** This application hasn't called us before; set up application AND per-thread +** data. Of course, just in case a thread from this same application is calling +** us simultaneously, we better lock our application data-creation mutex. We +** also need to recheck for data after we acquire the lock because WE might be +** that other thread that was too late to create the data and the first thread +** in will have created it. +*/ + NXLock(gLibLock); + + if (!(app_data = (libdata_t *) get_app_data(id))) { + app_data = (libdata_t *) malloc(sizeof(libdata_t)); + + if (app_data) { + memset(app_data, 0, sizeof(libdata_t)); + + 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) { +/* +** Here we burn in the application data that we were trying to get by calling +** get_app_data(). Next time we call the first function, we'll get this data +** we're just now setting. We also go on here to establish the per-thread data +** for the calling thread, something we'll have to do on each application +** thread the first time it calls us. +*/ + err = set_app_data(gLibId, app_data); + + if (err) { + free(app_data); + app_data = (libdata_t *) NULL; + err = ENOMEM; + } + else { + /* create key for thread-specific data... */ + err = NXKeyCreate(DisposeThreadData, (void *) NULL, &key); + + if (err) /* (no more keys left?) */ + key = -1; + + app_data->perthreadkey = key; + } + } + } + } + + NXUnlock(gLibLock); + } + + if (app_data) { + key = app_data->perthreadkey; + + if (key != -1 /* couldn't create a key? no thread data */ + && !(err = NXKeyGetValue(key, (void **) &thread_data)) + && !thread_data) { +/* +** Allocate the per-thread data for the calling thread. Regardless of whether +** there was already application data or not, this may be the first call by a +** a new thread. The fact that we allocation 20 bytes on a pointer is not very +** important, this just helps to demonstrate that we can have arbitrarily +** complex per-thread data. +*/ + thread_data = (libthreaddata_t *) 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; + } + + if ((err = NXKeySetValue(key, thread_data))) { + 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; + + if (tenbytes) + free(tenbytes); + + free(data); + } + + return 0; +} + +void DisposeThreadData(void *data) +{ + if (data) { + void *twentybytes = ((libthreaddata_t *) data)->twentybytes; + + if (twentybytes) + free(twentybytes); + + free(data); + } +} -- cgit v1.2.1 From 99dcd33f048598f209ea430b8d9f88bc7bb2bce9 Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Wed, 28 Feb 2007 05:15:56 +0000 Subject: protect from themselves those who need it --- lib/nwlib.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'lib/nwlib.c') diff --git a/lib/nwlib.c b/lib/nwlib.c index b0eea56c7..8b873e7f9 100644 --- a/lib/nwlib.c +++ b/lib/nwlib.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2004, Daniel Stenberg, , et al. + * Copyright (C) 1998 - 2007, Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms @@ -21,6 +21,8 @@ * $Id$ ***************************************************************************/ +#if !defined(WIN32) && !defined(_WIN32) && !defined(__WIN32__) && !defined(_WIN32_WCE) + #include #include #include @@ -298,3 +300,5 @@ void DisposeThreadData(void *data) free(data); } } + +#endif /* Not for Windows */ -- cgit v1.2.1 From 4fdb42377b660f7c415f1f9b980aa2afc452c3b2 Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Wed, 28 Feb 2007 15:10:20 +0000 Subject: proper symbol definition check for Novell NetWare --- lib/nwlib.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/nwlib.c') diff --git a/lib/nwlib.c b/lib/nwlib.c index 8b873e7f9..846353aba 100644 --- a/lib/nwlib.c +++ b/lib/nwlib.c @@ -21,7 +21,7 @@ * $Id$ ***************************************************************************/ -#if !defined(WIN32) && !defined(_WIN32) && !defined(__WIN32__) && !defined(_WIN32_WCE) +#ifdef NETWARE /* Novell NetWare */ #include #include @@ -301,4 +301,4 @@ void DisposeThreadData(void *data) } } -#endif /* Not for Windows */ +#endif /* NETWARE */ -- cgit v1.2.1 From 3fc6faf1ae48f15f627ccd4fae92d9c085876d42 Mon Sep 17 00:00:00 2001 From: Gunter Knauf Date: Sat, 30 Jun 2007 20:02:51 +0000 Subject: enabled building for NetWare CLIB architecture. --- lib/nwlib.c | 39 +++++++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 6 deletions(-) (limited to 'lib/nwlib.c') diff --git a/lib/nwlib.c b/lib/nwlib.c index 846353aba..da155ac90 100644 --- a/lib/nwlib.c +++ b/lib/nwlib.c @@ -23,9 +23,12 @@ #ifdef NETWARE /* Novell NetWare */ +#include + +#ifdef __NOVELL_LIBC__ +/* For native LibC-based NLM we need to register as a real lib. */ #include #include -#include #include #include #include @@ -148,7 +151,7 @@ void _NonAppStop( void ) ** we return a non-zero value. Right now, there isn't any reason not to allow ** it. */ -int _NonAppCheckUnload( void ) +int _NonAppCheckUnload( void ) { return 0; } @@ -275,10 +278,10 @@ int GetOrSetUpData(int id, libdata_t **appData, return err; } -int DisposeLibraryData( void *data) +int DisposeLibraryData( void *data ) { if (data) { - void *tenbytes = ((libdata_t *) data)->tenbytes; + void *tenbytes = ((libdata_t *) data)->tenbytes; if (tenbytes) free(tenbytes); @@ -289,10 +292,10 @@ int DisposeLibraryData( void *data) return 0; } -void DisposeThreadData(void *data) +void DisposeThreadData( void *data ) { if (data) { - void *twentybytes = ((libthreaddata_t *) data)->twentybytes; + void *twentybytes = ((libthreaddata_t *) data)->twentybytes; if (twentybytes) free(twentybytes); @@ -301,4 +304,28 @@ void DisposeThreadData(void *data) } } +#else /* __NOVELL_LIBC__ */ +/* For native CLib-based NLM seems we can do a bit more simple. */ +#include + +/* Make the CLIB Ctx stuff link */ +/* +#include +#include +NETDB_DEFINE_CONTEXT +*/ + +int main ( void ) +{ + /* initialize any globals here... */ + + /* do this if any global initializing was done + SynchronizeStart(); + */ + ExitThread (TSR_THREAD, 0); + return 0; +} + +#endif /* __NOVELL_LIBC__ */ + #endif /* NETWARE */ -- cgit v1.2.1 From c0095d6dd904c6ad82fe834cbef790ca4d231944 Mon Sep 17 00:00:00 2001 From: Gunter Knauf Date: Wed, 11 Jul 2007 21:47:31 +0000 Subject: removed now obsolete NETDB_DEFINE_CONTEXT macro calls. --- lib/nwlib.c | 7 ------- 1 file changed, 7 deletions(-) (limited to 'lib/nwlib.c') diff --git a/lib/nwlib.c b/lib/nwlib.c index da155ac90..9c0cbaaa5 100644 --- a/lib/nwlib.c +++ b/lib/nwlib.c @@ -308,13 +308,6 @@ void DisposeThreadData( void *data ) /* For native CLib-based NLM seems we can do a bit more simple. */ #include -/* Make the CLIB Ctx stuff link */ -/* -#include -#include -NETDB_DEFINE_CONTEXT -*/ - int main ( void ) { /* initialize any globals here... */ -- cgit v1.2.1 From cbd1a77ec24e397d05f20c6de106625676343c9d Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 7 Nov 2007 09:21:35 +0000 Subject: if () => if() while () => while() and some other minor re-indentings --- lib/nwlib.c | 82 ++++++++++++++++++++++++++++++------------------------------- 1 file changed, 41 insertions(+), 41 deletions(-) (limited to 'lib/nwlib.c') diff --git a/lib/nwlib.c b/lib/nwlib.c index 9c0cbaaa5..8fc41b4a7 100644 --- a/lib/nwlib.c +++ b/lib/nwlib.c @@ -82,7 +82,7 @@ int _NonAppStart( void *NLMHandle, const char **messages ) { NX_LOCK_INFO_ALLOC(liblock, "Per-Application Data Lock", 0); - + #ifndef __GNUC__ #pragma unused(cmdLine) #pragma unused(loadDirPath) @@ -105,7 +105,7 @@ int _NonAppStart( void *NLMHandle, " memory allocations", AllocSignature); - if (!gAllocTag) { + if(!gAllocTag) { OutputToScreen(errorScreen, "Unable to allocate resource tag for " "library memory allocations.\n"); return -1; @@ -113,7 +113,7 @@ int _NonAppStart( void *NLMHandle, gLibId = register_library(DisposeLibraryData); - if (gLibId < -1) { + if(gLibId < -1) { OutputToScreen(errorScreen, "Unable to register library with kernel.\n"); return -1; } @@ -121,8 +121,8 @@ int _NonAppStart( void *NLMHandle, gLibHandle = NLMHandle; gLibLock = NXMutexAlloc(0, 0, &liblock); - - if (!gLibLock) { + + if(!gLibLock) { OutputToScreen(errorScreen, "Unable to allocate library data lock.\n"); return -1; } @@ -175,7 +175,7 @@ int GetOrSetUpData(int id, libdata_t **appData, */ app_data = (libdata_t *) get_app_data(id); - if (!app_data) { + if(!app_data) { /* ** This application hasn't called us before; set up application AND per-thread ** data. Of course, just in case a thread from this same application is calling @@ -186,25 +186,25 @@ int GetOrSetUpData(int id, libdata_t **appData, */ NXLock(gLibLock); - if (!(app_data = (libdata_t *) get_app_data(id))) { + if(!(app_data = (libdata_t *) get_app_data(id))) { app_data = (libdata_t *) malloc(sizeof(libdata_t)); - if (app_data) { + if(app_data) { memset(app_data, 0, sizeof(libdata_t)); - + app_data->tenbytes = malloc(10); app_data->lock = NXMutexAlloc(0, 0, &liblock); - - if (!app_data->tenbytes || !app_data->lock) { - if (app_data->lock) + + 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) { + + if(app_data) { /* ** Here we burn in the application data that we were trying to get by calling ** get_app_data(). Next time we call the first function, we'll get this data @@ -213,8 +213,8 @@ int GetOrSetUpData(int id, libdata_t **appData, ** thread the first time it calls us. */ err = set_app_data(gLibId, app_data); - - if (err) { + + if(err) { free(app_data); app_data = (libdata_t *) NULL; err = ENOMEM; @@ -222,23 +222,23 @@ int GetOrSetUpData(int id, libdata_t **appData, else { /* create key for thread-specific data... */ err = NXKeyCreate(DisposeThreadData, (void *) NULL, &key); - - if (err) /* (no more keys left?) */ + + if(err) /* (no more keys left?) */ key = -1; - + app_data->perthreadkey = key; } } } } - + NXUnlock(gLibLock); } - if (app_data) { + if(app_data) { key = app_data->perthreadkey; - - if (key != -1 /* couldn't create a key? no thread data */ + + if(key != -1 /* couldn't create a key? no thread data */ && !(err = NXKeyGetValue(key, (void **) &thread_data)) && !thread_data) { /* @@ -249,18 +249,18 @@ int GetOrSetUpData(int id, libdata_t **appData, ** complex per-thread data. */ thread_data = (libthreaddata_t *) malloc(sizeof(libthreaddata_t)); - - if (thread_data) { + + if(thread_data) { thread_data->_errno = 0; thread_data->twentybytes = malloc(20); - - if (!thread_data->twentybytes) { + + if(!thread_data->twentybytes) { free(thread_data); thread_data = (libthreaddata_t *) NULL; err = ENOMEM; } - - if ((err = NXKeySetValue(key, thread_data))) { + + if((err = NXKeySetValue(key, thread_data))) { free(thread_data->twentybytes); free(thread_data); thread_data = (libthreaddata_t *) NULL; @@ -269,10 +269,10 @@ int GetOrSetUpData(int id, libdata_t **appData, } } - if (appData) + if(appData) *appData = app_data; - if (threadData) + if(threadData) *threadData = thread_data; return err; @@ -280,12 +280,12 @@ int GetOrSetUpData(int id, libdata_t **appData, int DisposeLibraryData( void *data ) { - if (data) { + if(data) { void *tenbytes = ((libdata_t *) data)->tenbytes; - - if (tenbytes) + + if(tenbytes) free(tenbytes); - + free(data); } @@ -294,12 +294,12 @@ int DisposeLibraryData( void *data ) void DisposeThreadData( void *data ) { - if (data) { + if(data) { void *twentybytes = ((libthreaddata_t *) data)->twentybytes; - - if (twentybytes) + + if(twentybytes) free(twentybytes); - + free(data); } } @@ -312,7 +312,7 @@ int main ( void ) { /* initialize any globals here... */ - /* do this if any global initializing was done + /* do this if any global initializing was done SynchronizeStart(); */ ExitThread (TSR_THREAD, 0); -- cgit v1.2.1 From 64e88ff6a7e282754c3925c05d1624aa5a30c112 Mon Sep 17 00:00:00 2001 From: Gunter Knauf Date: Wed, 23 Jan 2008 02:10:40 +0000 Subject: removed inclusion of libcurl memory debug headers since this lib stub is a well proofed method suggested by Novell. This enables usage of the stub with language bindings. --- lib/nwlib.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'lib/nwlib.c') diff --git a/lib/nwlib.c b/lib/nwlib.c index 8fc41b4a7..194c6757a 100644 --- a/lib/nwlib.c +++ b/lib/nwlib.c @@ -35,8 +35,6 @@ #include #include -#include "memory.h" -#include "memdebug.h" typedef struct { -- cgit v1.2.1 From 5ee3f41e0db53fea9b0521a137c8e412f053d476 Mon Sep 17 00:00:00 2001 From: Gunter Knauf Date: Wed, 23 Jan 2008 02:12:13 +0000 Subject: happy new year --- lib/nwlib.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/nwlib.c') diff --git a/lib/nwlib.c b/lib/nwlib.c index 194c6757a..3a3e28ef8 100644 --- a/lib/nwlib.c +++ b/lib/nwlib.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2007, Daniel Stenberg, , et al. + * Copyright (C) 1998 - 2008, Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms -- cgit v1.2.1 From 59e378f48fed849e8e41f0bc6a10bf7a1732ae8a Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Sat, 6 Sep 2008 05:29:05 +0000 Subject: remove unnecessary typecasting of malloc() --- lib/nwlib.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/nwlib.c') diff --git a/lib/nwlib.c b/lib/nwlib.c index 3a3e28ef8..185042b29 100644 --- a/lib/nwlib.c +++ b/lib/nwlib.c @@ -185,7 +185,7 @@ int GetOrSetUpData(int id, libdata_t **appData, NXLock(gLibLock); if(!(app_data = (libdata_t *) get_app_data(id))) { - app_data = (libdata_t *) malloc(sizeof(libdata_t)); + app_data = malloc(sizeof(libdata_t)); if(app_data) { memset(app_data, 0, sizeof(libdata_t)); @@ -246,7 +246,7 @@ int GetOrSetUpData(int id, libdata_t **appData, ** important, this just helps to demonstrate that we can have arbitrarily ** complex per-thread data. */ - thread_data = (libthreaddata_t *) malloc(sizeof(libthreaddata_t)); + thread_data = malloc(sizeof(libthreaddata_t)); if(thread_data) { thread_data->_errno = 0; -- cgit v1.2.1 From b2f430898053258622eebee3328f03441367a32c Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Tue, 27 Oct 2009 16:38:42 +0000 Subject: Fix Pelles C Win32 target compilation issues --- lib/nwlib.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'lib/nwlib.c') diff --git a/lib/nwlib.c b/lib/nwlib.c index 185042b29..cb1c5dd02 100644 --- a/lib/nwlib.c +++ b/lib/nwlib.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2008, Daniel Stenberg, , et al. + * Copyright (C) 1998 - 2009, Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms @@ -319,4 +319,10 @@ int main ( void ) #endif /* __NOVELL_LIBC__ */ +#else /* NETWARE */ + +#ifdef __POCC__ +# pragma warn(disable:2024) /* Disable warning #2024: Empty input file */ +#endif + #endif /* NETWARE */ -- cgit v1.2.1 From 2309b4e330b96bc2e1f8e36b6184015e59544037 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 24 Mar 2010 11:02:54 +0100 Subject: remove the CVSish $Id$ lines --- lib/nwlib.c | 1 - 1 file changed, 1 deletion(-) (limited to 'lib/nwlib.c') diff --git a/lib/nwlib.c b/lib/nwlib.c index cb1c5dd02..f9c8a4298 100644 --- a/lib/nwlib.c +++ b/lib/nwlib.c @@ -18,7 +18,6 @@ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * - * $Id$ ***************************************************************************/ #ifdef NETWARE /* Novell NetWare */ -- cgit v1.2.1 From f1586cb4775681810afd8e6626e7842d459f3b85 Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Tue, 26 Jul 2011 17:23:27 +0200 Subject: stdio.h, stdlib.h, string.h, stdarg.h and ctype.h inclusion done in setup_once.h --- lib/nwlib.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'lib/nwlib.c') diff --git a/lib/nwlib.c b/lib/nwlib.c index f9c8a4298..c87ca0d29 100644 --- a/lib/nwlib.c +++ b/lib/nwlib.c @@ -20,14 +20,12 @@ * ***************************************************************************/ -#ifdef NETWARE /* Novell NetWare */ +#include "setup.h" -#include +#ifdef NETWARE /* Novell NetWare */ #ifdef __NOVELL_LIBC__ /* For native LibC-based NLM we need to register as a real lib. */ -#include -#include #include #include #include -- cgit v1.2.1 From 8a2be299f4c91a87014b35bcf6b75f91ab477262 Mon Sep 17 00:00:00 2001 From: Marc Hoersken Date: Fri, 14 Sep 2012 00:44:16 +0200 Subject: checksrc: Fixed line length and comment indentation --- lib/nwlib.c | 111 ++++++++++++++++++++++++++++++------------------------------ 1 file changed, 56 insertions(+), 55 deletions(-) (limited to 'lib/nwlib.c') diff --git a/lib/nwlib.c b/lib/nwlib.c index c87ca0d29..a7ea17bb2 100644 --- a/lib/nwlib.c +++ b/lib/nwlib.c @@ -55,9 +55,9 @@ rtag_t gAllocTag = (rtag_t) NULL; NXMutex_t *gLibLock = (NXMutex_t *) NULL; /* internal library function prototypes... */ -int DisposeLibraryData ( void * ); -void DisposeThreadData ( void * ); -int GetOrSetUpData ( int id, libdata_t **data, libthreaddata_t **threaddata ); +int DisposeLibraryData( void * ); +void DisposeThreadData( void * ); +int GetOrSetUpData( int id, libdata_t **data, libthreaddata_t **threaddata ); int _NonAppStart( void *NLMHandle, @@ -90,12 +90,12 @@ int _NonAppStart( void *NLMHandle, #pragma unused(messages) #endif -/* -** Here we process our command line, post errors (to the error screen), -** perform initializations and anything else we need to do before being able -** to accept calls into us. If we succeed, we return non-zero and the NetWare -** Loader will leave us up, otherwise we fail to load and get dumped. -*/ + /* + * Here we process our command line, post errors (to the error screen), + * perform initializations and anything else we need to do before being able + * to accept calls into us. If we succeed, we return non-zero and the NetWare + * Loader will leave us up, otherwise we fail to load and get dumped. + */ gAllocTag = AllocateResourceTag(NLMHandle, " memory allocations", AllocSignature); @@ -126,9 +126,9 @@ int _NonAppStart( void *NLMHandle, } /* -** Here we clean up any resources we allocated. Resource tags is a big part -** of what we created, but NetWare doesn't ask us to free those. -*/ + * Here we clean up any resources we allocated. Resource tags is a big part + * of what we created, but NetWare doesn't ask us to free those. + */ void _NonAppStop( void ) { (void) unregister_library(gLibId); @@ -136,16 +136,16 @@ void _NonAppStop( void ) } /* -** This function cannot be the first in the file for if the file is linked -** first, then the check-unload function's offset will be nlmname.nlm+0 -** which is how to tell that there isn't one. When the check function is -** first in the linked objects, it is ambiguous. For this reason, we will -** put it inside this file after the stop function. -** -** Here we check to see if it's alright to ourselves to be unloaded. If not, -** we return a non-zero value. Right now, there isn't any reason not to allow -** it. -*/ + * This function cannot be the first in the file for if the file is linked + * first, then the check-unload function's offset will be nlmname.nlm+0 + * which is how to tell that there isn't one. When the check function is + * first in the linked objects, it is ambiguous. For this reason, we will + * put it inside this file after the stop function. + * + * Here we check to see if it's alright to ourselves to be unloaded. If not, + * we return a non-zero value. Right now, there isn't any reason not to allow + * it. + */ int _NonAppCheckUnload( void ) { return 0; @@ -163,22 +163,22 @@ int GetOrSetUpData(int id, libdata_t **appData, err = 0; thread_data = (libthreaddata_t *) NULL; -/* -** Attempt to get our data for the application calling us. This is where we -** store whatever application-specific information we need to carry in support -** of calling applications. -*/ + /* + * Attempt to get our data for the application calling us. This is where we + * store whatever application-specific information we need to carry in + * support of calling applications. + */ app_data = (libdata_t *) get_app_data(id); if(!app_data) { -/* -** This application hasn't called us before; set up application AND per-thread -** data. Of course, just in case a thread from this same application is calling -** us simultaneously, we better lock our application data-creation mutex. We -** also need to recheck for data after we acquire the lock because WE might be -** that other thread that was too late to create the data and the first thread -** in will have created it. -*/ + /* + * This application hasn't called us before; set up application AND + * per-thread data. Of course, just in case a thread from this same + * application is calling us simultaneously, we better lock our application + * data-creation mutex. We also need to recheck for data after we acquire + * the lock because WE might be that other thread that was too late to + * create the data and the first thread in will have created it. + */ NXLock(gLibLock); if(!(app_data = (libdata_t *) get_app_data(id))) { @@ -200,13 +200,14 @@ int GetOrSetUpData(int id, libdata_t **appData, } if(app_data) { -/* -** Here we burn in the application data that we were trying to get by calling -** get_app_data(). Next time we call the first function, we'll get this data -** we're just now setting. We also go on here to establish the per-thread data -** for the calling thread, something we'll have to do on each application -** thread the first time it calls us. -*/ + /* + * Here we burn in the application data that we were trying to get + * by calling get_app_data(). Next time we call the first function, + * we'll get this data we're just now setting. We also go on here to + * establish the per-thread data for the calling thread, something + * we'll have to do on each application thread the first time + * it calls us. + */ err = set_app_data(gLibId, app_data); if(err) { @@ -236,13 +237,13 @@ int GetOrSetUpData(int id, libdata_t **appData, if(key != -1 /* couldn't create a key? no thread data */ && !(err = NXKeyGetValue(key, (void **) &thread_data)) && !thread_data) { -/* -** Allocate the per-thread data for the calling thread. Regardless of whether -** there was already application data or not, this may be the first call by a -** a new thread. The fact that we allocation 20 bytes on a pointer is not very -** important, this just helps to demonstrate that we can have arbitrarily -** complex per-thread data. -*/ + /* + * Allocate the per-thread data for the calling thread. Regardless of + * whether there was already application data or not, this may be the + * first call by a new thread. The fact that we allocation 20 bytes on + * a pointer is not very important, this just helps to demonstrate that + * we can have arbitrarily complex per-thread data. + */ thread_data = malloc(sizeof(libthreaddata_t)); if(thread_data) { @@ -305,13 +306,13 @@ void DisposeThreadData( void *data ) int main ( void ) { - /* initialize any globals here... */ + /* initialize any globals here... */ - /* do this if any global initializing was done - SynchronizeStart(); - */ - ExitThread (TSR_THREAD, 0); - return 0; + /* do this if any global initializing was done + SynchronizeStart(); + */ + ExitThread (TSR_THREAD, 0); + return 0; } #endif /* __NOVELL_LIBC__ */ -- cgit v1.2.1 From ee588fe088077785d9ad9263e03e1e525b074261 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Sat, 17 Nov 2012 00:59:42 +0100 Subject: mem-include-scan: verify memory #includes If we use memory functions (malloc, free, strdup etc) in C sources in libcurl and we fail to include curl_memory.h or memdebug.h we either fail to properly support user-provided memory callbacks or the memory leak system of the test suite fails. After Ajit's report of a failure in the first category in http_proxy.c, I spotted a few in the second category as well. These problems are now tested for by test 1132 which runs a perl program that scans for and attempts to check that we use the correct include files if a memory related function is used in the source code. Reported by: Ajit Dhumale Bug: http://curl.haxx.se/mail/lib-2012-11/0125.html --- lib/nwlib.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'lib/nwlib.c') diff --git a/lib/nwlib.c b/lib/nwlib.c index a7ea17bb2..c67342a08 100644 --- a/lib/nwlib.c +++ b/lib/nwlib.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2009, Daniel Stenberg, , et al. + * Copyright (C) 1998 - 2012, Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms @@ -32,6 +32,9 @@ #include #include +#include "curl_memory.h" +/* The last #include file should be: */ +#include "memdebug.h" typedef struct { -- cgit v1.2.1