static int Fclose(int fd) { CloseHandle(fhand[fd].hand); freeHandle(fd); return (0); }
static int Nclose(int fd) { closesocket(fhand[fd].sock); freeHandle(fd); return (0); }
/* * Threaded file open. */ static int Fopen(const char* path, int mode) { int fd; fd = allocHandle(); if (fd == -1) { return (-1); } switch (mode) { case JOPEN_READ: fhand[fd].hand = CreateFile(path, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); break; case JOPEN_WRITE: fhand[fd].hand = CreateFile(path, GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); break; case JOPEN_APPEND: fhand[fd].hand = CreateFile(path, GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); break; case JOPEN_READWRITE: fhand[fd].hand = CreateFile(path, GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); break; default: freeHandle(fd); return (-1); } // printf("Opening %s on %d %x\n", path, fd, fhand[fd].hand); if (fhand[fd].hand == INVALID_HANDLE_VALUE) { freeHandle(fd); return (-1); } else { return (fd); } }
void btSimpleBroadphase::destroyProxy(btBroadphaseProxy* proxyOrg,btDispatcher* dispatcher) { btSimpleBroadphaseProxy* proxy0 = static_cast<btSimpleBroadphaseProxy*>(proxyOrg); freeHandle(proxy0); m_pairCache->removeOverlappingPairsContainingProxy(proxyOrg,dispatcher); //validate(); }
static int elektraResolveFilename (Key * parentKey, ElektraResolveTempfile tmpFile) { int rc = 0; void * handle = elektraInvokeOpen ("resolver", 0, 0); if (!handle) { rc = -1; goto RESOLVE_FAILED; } ElektraResolved * resolved = NULL; typedef ElektraResolved * (*resolveFileFunc) (elektraNamespace, const char *, ElektraResolveTempfile, Key *); resolveFileFunc resolveFunc = *(resolveFileFunc *) elektraInvokeGetFunction (handle, "filename"); if (!resolveFunc) { rc = -1; goto RESOLVE_FAILED; } typedef void (*freeHandleFunc) (ElektraResolved *); freeHandleFunc freeHandle = *(freeHandleFunc *) elektraInvokeGetFunction (handle, "freeHandle"); if (!freeHandle) { rc = -1; goto RESOLVE_FAILED; } resolved = resolveFunc (keyGetNamespace (parentKey), keyString (parentKey), tmpFile, parentKey); if (!resolved) { rc = -1; goto RESOLVE_FAILED; } else { keySetString (parentKey, resolved->fullPath); freeHandle (resolved); } RESOLVE_FAILED: elektraInvokeClose (handle, 0); return rc; }
/* * Threaded socket accept. */ static int Naccept(int fd, struct sockaddr* addr, size_t* len) { int nfd; nfd = allocHandle(); if (nfd == -1) { return (-1); } fhand[nfd].sock = WSAAccept(fhand[fd].sock, addr, len, NULL, 0); if (fhand[nfd].sock == INVALID_SOCKET) { freeHandle(nfd); return (-1); } return (nfd); }
/******************************************************************* * Function: getIndexForSystemID * Description: return an index for a unique system id. * ****************************************************************/ UInt16 getIndexForSystemID (DmOpenRef SystemDB, UInt16 sysid) { UInt16 i, id, index = 0; /* get the number of system records. note that we cant just use totalItems++ because systems can be added and deleted at will... */ UInt16 totalItems = DmNumRecordsInCategory (SystemDB, dmAllCategories); Boolean stop = false; /* iterate through the records, and we will return the highest one it higher than the highest current value. */ for (i = 0; i < totalItems && !stop; i++) { MemHandle scr; if ((scr = MemHandleNew (1))) { id = getSIDForSystemIndex (SystemDB, i); if (id == sysid) index = i; freeHandle (scr); } } return index; }
/******************************************************************* * Function: getUniqueSystemID * Description: return a unique system id that can be assigned to a * new system. * Note: SystemID 0 is reserved for the Unfiled system. Unfiled is * where beamed accounts go when they are first received if they * dont have anywhere else to go. * ****************************************************************/ UInt16 getUniqueSystemID (DmOpenRef SystemDB) { UInt16 i, id; /* get the number of system records. note that we cant just use totalItems++ because systems can be added and deleted at will... */ UInt16 totalItems = DmNumRecordsInCategory (SystemDB, dmAllCategories); UInt16 max = 0; /* iterate through the records, and we will return the highest one it higher than the highest current value. */ for (i = 0; i < totalItems; i++) { MemHandle scr; if ((scr = MemHandleNew (1))) { id = getSIDForSystemIndex (SystemDB, i); if (id > max) max = id; freeHandle (scr); } } return max + 1; }
/* * Threaded socket create. */ static int Nsocket(int stream) { int fd; fd = allocHandle(); if (fd == -1) { return (-1); } if (stream == 0) { fhand[fd].sock = WSASocket(AF_INET, SOCK_DGRAM, 0, NULL, 0, 0); } else { fhand[fd].sock = WSASocket(AF_INET, SOCK_STREAM, 0, NULL, 0, 0); } if (fhand[fd].sock == INVALID_SOCKET) { freeHandle(fd); return (-1); } else { return (fd); } }