// cs/samlib.h // Miscellaneous handy functions // 26-01-1996: creation // 15-02-1996: type boolean removed ifndef _SAMLIB_H_ define _SAMLIB_H_ ifdef HUSH include <hush/bool.h> else # if !defined(__GNUC__) typedef bool int; # endif endif include <sys/types.h> // macro's if !defined(MIN) define MIN(a,b) (((a) < (b)) ? (a) : (b)) endif if !defined(MAX) define MAX(a,b) (((a) > (b)) ? (a) : (b)) endif // typedefs if !defined(NO_TYPES) typedef char int8; typedef unsigned char uint8; typedef unsigned char byte; typedef short int16; typedef unsigned short uint16; typedef int int32; typedef unsigned int uint32; typedef long long int64; typedef unsigned long long uint64; endif extern bool log_active; // default false // functions bool data_available(int fd); // true : data can be read from filedescriptor 'fd' // false: no data can be read int read_nonblock(int fd, char* buffer, int maxbytes); inline void int8_to_buffer(char* buf, int8 val) { buf[0] = val & 0xff; } inline void int16_to_buffer(char* buf, int16 val) { buf[0] = (val >> 8) & 0xff; buf[1] = val & 0xff; } inline void int32_to_buffer(char* buf, int32 val) { buf[0] = (val >> 24) & 0xff; buf[1] = (val >> 16) & 0xff; buf[2] = (val >> 8) & 0xff; buf[3] = val & 0xff; } inline int buffer_to_int8(const char* buf) { return (int)buf[0]; } inline int buffer_to_int16(const char* buf) { return ((int)buf[0] << 8) | ((int)buf[1]); } inline int buffer_to_int32(const char* buf) { return ((int)buf[0] << 24) | ((int)buf[1] << 16) | ((int)buf[2] << 8) | ((int)buf[3]); } int read_package(int fd, char* buf, int maxnrbytes); int write_package(int fd, const char* buf, int nrbytes); void unbuffer_stdin(); void restore_stdin(); void unbuffer_stdout(); void warn(const char* str, ...); void halt(const char* str, ...); void write_to_log(const char* logstr, ...); endif _SAMLIB_H_
Hush Online Technology
hush@cs.vu.nl
09/09/98 |
![]() |
![]() |