From 684f52a149bb07baec157b7f203af37444a708a1 Mon Sep 17 00:00:00 2001 From: Simone Piccardi Date: Sat, 16 Aug 2003 18:30:21 +0000 Subject: [PATCH] Added to library function to check endianess --- sources/Gapil.h | 6 +++++- sources/Makefile | 3 ++- sources/endian.c | 16 ++++++---------- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/sources/Gapil.h b/sources/Gapil.h index 0db517d..c6cbfea 100644 --- a/sources/Gapil.h +++ b/sources/Gapil.h @@ -23,7 +23,7 @@ * * Author: S. Piccardi * - * $Id: Gapil.h,v 1.11 2003/05/06 11:29:16 piccardi Exp $ + * $Id: Gapil.h,v 1.12 2003/08/16 18:30:21 piccardi Exp $ * *****************************************************************************/ #include /* IPC semaphore declarations */ @@ -122,3 +122,7 @@ void * CreateShm(char * shm_name, off_t shm_size, int perm, int fill); void * FindShm(char * shm_name, off_t shm_size); /* Function RemoveShm: remove a POSIX shared memory */ int RemoveShm(char * shm_name); +/* + * General purpose functions. See corresponding .c + */ +int endian(void); diff --git a/sources/Makefile b/sources/Makefile index 39db81d..82ae8e4 100644 --- a/sources/Makefile +++ b/sources/Makefile @@ -8,7 +8,8 @@ CFLAGJ= -L./ -lgapil LIB = libgapil.so -OBJ = FullRead.o FullWrite.o SigHand.o Mutex.o SharedMem.o LockFile.o DirScan.o +OBJ = FullRead.o FullWrite.o SigHand.o Mutex.o SharedMem.o LockFile.o \ + DirScan.o endian.o FINAL = forktest errcode echo echod daytimed iterdaytimed daytime testfopen \ testren fortune fortuned mqfortune mqfortuned flock myls dirmonitor \ diff --git a/sources/endian.c b/sources/endian.c index 0505b36..d375d97 100644 --- a/sources/endian.c +++ b/sources/endian.c @@ -23,12 +23,11 @@ * Author: S. Piccardi * May. 2003 * - * $Id: endian.c,v 1.4 2003/08/16 18:22:25 piccardi Exp $ + * $Id: endian.c,v 1.5 2003/08/16 18:30:21 piccardi Exp $ * ***************************************************************/ -#include -int main(int argc, char *argv[]) +int endian(void) { /* * Variables definition @@ -36,11 +35,8 @@ int main(int argc, char *argv[]) short magic, test; char * ptr; - magic = 0xABCD; /* endianess magic number */ - ptr = (char *) &magic; - printf("Upper = %x\n", ptr[1]); - printf("Lower = %x\n", ptr[0]); - test = (ptr[1]<<8) + (ptr[0]&0xFF); - printf("magic=%x, test=%x\n", magic, test); - return (magic == test); + magic = 0xABCD; /* endianess magic number */ + ptr = (char *) &magic; + test = (ptr[1]<<8) + (ptr[0]&0xFF); /* build value byte by byte */ + return (magic == test); /* if the same is little endian */ } -- 2.30.2