1 /* Util.h
2  *
3  * Copyright (c) 1996-2001 Mike Gleason, NCEMRSoft.
4  * All rights reserved.
5  *
6  */
7 
8 #ifndef _util_h_
9 #define _util_h_ 1
10 
11 typedef char string[160], str16[16], str32[32], str64[64];
12 typedef char longstring[512];
13 typedef char pathname[512];
14 
15 #ifndef PTRZERO
16 #	define PTRZERO(p,siz)  (void) memset(p, 0, (size_t) (siz))
17 #endif
18 
19 #define ZERO(a)	PTRZERO(&(a), sizeof(a))
20 #define STREQ(a,b) (strcmp(a,b) == 0)
21 #define STRNEQ(a,b,s) (strncmp(a,b,(size_t)(s)) == 0)
22 
23 #ifndef ISTRCMP
24 #	ifdef HAVE_STRCASECMP
25 #		define ISTRCMP strcasecmp
26 #		define ISTRNCMP strncasecmp
27 #	else
28 #		define ISTRCMP strcmp
29 #		define ISTRNCMP strncmp
30 #	endif
31 #endif
32 
33 #define ISTREQ(a,b) (ISTRCMP(a,b) == 0)
34 #define ISTRNEQ(a,b,s) (ISTRNCMP(a,b,(size_t)(s)) == 0)
35 
36 typedef int (*cmp_t)(const void *, const void *);
37 #define QSORT(base,n,s,cmp) \
38 	qsort(base, (size_t)(n), (size_t)(s), (cmp_t)(cmp))
39 
40 #define BSEARCH(key,base,n,s,cmp) \
41 	bsearch(key, base, (size_t)(n), (size_t)(s), (cmp_t)(cmp))
42 
43 /* For Error(): */
44 #define kDoPerror		1
45 #define kDontPerror		0
46 
47 #define kClosedFileDescriptor (-1)
48 
49 #define SZ(a) ((size_t) (a))
50 
51 #ifndef F_OK
52 #	define F_OK 0
53 #endif
54 
55 #ifdef HAVE_REMOVE
56 #	define UNLINK remove
57 #else
58 #	define UNLINK unlink
59 #endif
60 
61 #ifndef SEEK_SET
62 #	define SEEK_SET    0
63 #	define SEEK_CUR    1
64 #	define SEEK_END    2
65 #endif  /* SEEK_SET */
66 
67 #ifdef SETVBUF_REVERSED
68 #	define SETVBUF(a,b,c,d) setvbuf(a,c,b,d)
69 #else
70 #	define SETVBUF setvbuf
71 #endif
72 
73 
74 /* Util.c */
75 char *FGets(char *, size_t, FILE *);
76 struct passwd *GetPwByName(void);
77 void GetHomeDir(char *, size_t);
78 void GetUsrName(char *, size_t);
79 void CloseFile(FILE **);
80 void PrintF(const FTPCIPtr cip, const char *const fmt, ...)
81 #if (defined(__GNUC__)) && (__GNUC__ >= 2)
82 __attribute__ ((format (printf, 2, 3)))
83 #endif
84 ;
85 void Error(const FTPCIPtr cip, const int pError, const char *const fmt, ...)
86 #if (defined(__GNUC__)) && (__GNUC__ >= 2)
87 __attribute__ ((format (printf, 3, 4)))
88 #endif
89 ;
90 int GetSockBufSize(int sockfd, size_t *rsize, size_t *ssize);
91 int SetSockBufSize(int sockfd, size_t rsize, size_t ssize);
92 time_t UnMDTMDate(char *);
93 void Scramble(unsigned char *dst, size_t dsize, unsigned char *src, char *key);
94 #if defined(WIN32) || defined(_WINDOWS)
95 char *StrFindLocalPathDelim(const char *src);
96 char *StrRFindLocalPathDelim(const char *src);
97 void TVFSPathToLocalPath(char *dst);
98 void LocalPathToTVFSPath(char *dst);
99 int gettimeofday(struct timeval *const tp, void *junk);
100 #endif
101 
102 #ifdef HAVE_SIGACTION
103 void (*NcSignal(int signum, void (*handler)(int)))(int);
104 #elif !defined(NcSignal)
105 #	define NcSignal signal
106 #endif
107 
108 #endif	/* _util_h_ */
109