From: Simone Piccardi Date: Fri, 2 May 2003 09:56:41 +0000 (+0000) Subject: Rimetto anche i .h X-Git-Url: https://gapil.gnulinux.it/gitweb/?a=commitdiff_plain;h=b6b51ee53b49d44c381887da73086586acf6e379;p=gapil.git Rimetto anche i .h --- diff --git a/sources/Gapil.h b/sources/Gapil.h new file mode 100644 index 0000000..60b411a --- /dev/null +++ b/sources/Gapil.h @@ -0,0 +1,122 @@ +/* Gapil.h + * + * Copyright (C) 2002 Simone Piccardi + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ +/***************************************************************************** + * + * File Gapil.h: + * Set of definition for service routines + * + * Author: S. Piccardi + * + * $Id: Gapil.h,v 1.10 2003/05/02 09:56:41 piccardi Exp $ + * + *****************************************************************************/ +#include /* IPC semaphore declarations */ +#include /* IPC shared memory declarations */ +#include +#include +#include /* unix standard functions */ +#include /* file control (lock) functions */ +#include /* signal handling declarations */ +#include /* directory scan functions */ +/* + * Definition of semun struct; used to implement a MutexXXXX API To + * create a Mutex use an underlaying semaphore and init it; we put + * here all the needed data structures + */ +/* use this definition, get from the man pages */ +#if defined(__GNU_LIBRARY__) && !defined(_SEM_SEMUN_UNDEFINED) +/* union semun is defined by including */ +#else +/* according to X/OPEN we have to define it ourselves */ +union semun { + int val; /* value for SETVAL */ + struct semid_ds *buf; /* buffer for IPC_STAT, IPC_SET */ + unsigned short int *array; /* array for GETALL, SETALL */ + struct seminfo *__buf; /* buffer for IPC_INFO */ +}; +#endif +/* + * Mutex handling Functions + */ +/* Function MutexCreate: create a mutex. See Mutex.c */ +inline int MutexCreate(key_t ipc_key); +/* Function MutexFind: get the mutex ID given fomr IPC key. See Mutex.c */ +inline int MutexFind(key_t ipc_key); +/* Function MutexRead: read the current value of the mutex. See Mutex.c */ +inline int MutexRead(int sem_id); +/* Function MutexLock: to lock a mutex/semaphore. See Mutex.c */ +inline int MutexLock(int sem_id); +/* Function MutexUnlock: to unlock a mutex/semaphore. See Mutex.c */ +inline int MutexUnlock(int sem_id); +/* Function MutexRemove: remove the mutex/semphore. See Mutex.c */ +inline int MutexRemove(int sem_id); +/* Function CreateMutex: create a mutex (using file locking). See Mutex.c */ +inline int CreateMutex(const char *path_name); +/* Function UnlockMutex: find a mutex (using file locking). See Mutex.c */ +inline int FindMutex(const char *path_name); +/* Function LockMutex: acquire a mutex (using file locking). See Mutex.c */ +inline int LockMutex(int fd); +/* Function UnlockMutex: release a mutex (using file locking). See Mutex.c */ +inline int UnlockMutex(int fd); +/* Function ReadMutex: read a mutex (using file locking). See Mutex.c */ +inline int ReadMutex(int fd); +/* Function RemoveMutex: remove a mutex (using file locking). See Mutex.c */ +inline int RemoveMutex(const char *path_name); +/* + * Lock files function: to create and destroy lock files + */ +/* Function LockFile: create a lock file. See FileLock.c */ +inline int LockFile(const char* path_name); +/* Function UnlockFile: remove a lock file. See FileLock.c */ +inline int UnlockFile(const char* path_name); +/* + * Signal Handling Functions + */ +typedef void SigFunc(int); +/* Function Signal: Initialize a signal handler. See SigHand.c */ +SigFunc * Signal(int signo, SigFunc *func); +/* Function HandSigCHLD: to handle SIGCHILD. See SigHand.c */ +void HandSigCHLD(int sig); +/* + * Socket service functions + */ +/* Function FullRead: to read from a socket. See FullRead.c */ +ssize_t FullRead(int fd, void *buf, size_t count); +/* Function FullWrite: to read from a socket. See FullWrite.c */ +ssize_t FullWrite(int fd, const void *buf, size_t count); +/* + * File miscellaneous + */ +/* Function DirScan: simple scan for a directory. See DirScan.c */ +int DirScan(char * dirname, int(*compute)(struct dirent *)); +/* + * Shared memory handling functions. See SharedMem.c + */ +/* Function ShmCreate: create a SysV shared memory */ +void * ShmCreate(key_t ipc_key, int shm_size, int perm, int fill); +/* Function ShmFind: find an existing SysV shared memory */ +void * ShmFind(key_t ipc_key, int shm_size); +/* Function ShmRemove: remove a SysV shared memory */ +int ShmRemove(key_t ipc_key, void * shm_ptr); +/* Function CreateShm: create a POSIX shared memory */ +void * CreateShm(char * shm_name, off_t shm_size, int perm, int fill); +/* Function FindShm: find an existing POSIX shared memory */ +void * FindShm(char * shm_name, off_t shm_size); +/* Function RemoveShm: remove a POSIX shared memory */ +int RemoveShm(char * shm_name); diff --git a/sources/macros.h b/sources/macros.h new file mode 100644 index 0000000..9784c7a --- /dev/null +++ b/sources/macros.h @@ -0,0 +1,62 @@ +/* macros.h + * + * Copyright (C) 2000-2002 Simone Piccardi + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ +/* + * Endianess conversion for int and short types + */ +#define BE32_TO_LE32(val) ({typeof (val) v= (val); \ + (v>>24) | ((v>>8)&0xFF00) | (v<<24) | ((v<<8)&0xFF0000); } ) +#define BE16_TO_LE16(val) ({typeof (val) v= (val); (v>>8) | (v<<8); } ) +/* + * Define a protected, right typed, no side effects macro for min + */ +#define min(x, y) ({typeof (x) x_ = (x); typeof (y) y_ = (y); \ + x_ < y_ ? x_ : y_;}) +/* + * debugging print definition + */ +#ifdef IS_DAEMON +#define report(fmt, args...) UserNotify(fmt,##args) +#else +#define report(fmt, args...) printf(fmt,##args) +#endif /* IS_DAEMON */ + +#ifdef DEBUG /* done only on debugging */ +#define debug report +#else +#define debug(fmt, arg...) +#endif /* DEBUG */ + + +/* + * Just to print an hex dump of a buffer, + * ptr is the address, m is how many word per line + * and l how many lines + */ +#define PRINT_BUF(ptr, l, m) ({ \ + int _i, _j; \ + unsigned short *_ptr= (unsigned short *)(ptr); \ + for (_i = 0; _i< (int) l; _i++) { \ + printf("Val[%d]=", m * _i); \ + for (_j = 0; _j < (int) m; _j++) { \ + printf("%x ", *_ptr);\ + _ptr++;\ + }\ + printf("\n"); \ + }\ +})