1 /* Util.h
2  *
3  * Copyright (c) 1996-2005 Mike Gleason, NcFTP Software.
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 #if (defined(WIN32) || defined(_WINDOWS)) && !defined(__CYGWIN__)
24 #	define ISTRCMP _stricmp
25 #	define ISTRNCMP _strnicmp
26 #endif
27 
28 #ifndef ISTRCMP
29 #	ifdef HAVE_STRCASECMP
30 #		define ISTRCMP strcasecmp
31 #		define ISTRNCMP strncasecmp
32 #	else
33 #		define ISTRCMP strcmp
34 #		define ISTRNCMP strncmp
35 #	endif
36 #endif
37 
38 #define ISTREQ(a,b) (ISTRCMP(a,b) == 0)
39 #define ISTRNEQ(a,b,s) (ISTRNCMP(a,b,(size_t)(s)) == 0)
40 
41 typedef int (*cmp_t)(const void *, const void *);
42 #define QSORT(base,n,s,cmp) \
43 	qsort(base, (size_t)(n), (size_t)(s), (cmp_t)(cmp))
44 
45 #define BSEARCH(key,base,n,s,cmp) \
46 	bsearch(key, base, (size_t)(n), (size_t)(s), (cmp_t)(cmp))
47 
48 /* For FTPLogError(): */
49 #define kDoPerror		1
50 #define kDontPerror		0
51 
52 #define kClosedFileDescriptor (-1)
53 
54 #define SZ(a) ((size_t) (a))
55 
56 #ifndef F_OK
57 #	define F_OK 0
58 #endif
59 
60 #ifdef HAVE_REMOVE
61 #	define UNLINK remove
62 #else
63 #	define UNLINK unlink
64 #endif
65 
66 #ifndef SEEK_SET
67 #	define SEEK_SET    0
68 #	define SEEK_CUR    1
69 #	define SEEK_END    2
70 #endif  /* SEEK_SET */
71 
72 #ifdef SETVBUF_REVERSED
73 #	define SETVBUF(a,b,c,d) setvbuf(a,c,b,d)
74 #else
75 #	define SETVBUF setvbuf
76 #endif
77 
78 
79 /* Util.c */
80 #if (defined(WIN32) || defined(_WINDOWS)) && !defined(__CYGWIN__)
81 #else
82 int GetMyPwEnt(struct passwd *pwp, char *const pwbuf, size_t pwbufsize);
83 int GetPwUid(struct passwd *pwp, const uid_t uid, char *const pwbuf, size_t pwbufsize);
84 int GetPwNam(struct passwd *pwp, const char *const nam, char *const pwbuf, size_t pwbufsize);
85 #endif
86 void CloseFile(FILE **);
87 #if (defined(WIN32) || defined(_WINDOWS)) && !defined(__CYGWIN__)
88 int gettimeofday(struct timeval *const tp, void *junk);
89 #endif
90 
91 /* io_util.c */
92 void AutomaticallyUseASCIIModeDependingOnExtension(const FTPCIPtr cip, const char *const pathName, int *const xtype);
93 void FTPCheckForRestartModeAvailability(const FTPCIPtr cip);
94 int WaitForRemoteInput(const FTPCIPtr cip);
95 int WaitForRemoteOutput(const FTPCIPtr cip);
96 void FTPSetUploadSocketBufferSize(const FTPCIPtr cip);
97 
98 /* io_get.c, io_put.c */
99 int
100 FTPGetOneF(
101 	const FTPCIPtr cip,
102 	const char *const file,
103 	const char *dstfile,
104 	int xtype,
105 	const int fdtouse,
106 	longest_int expectedSize,
107 	time_t mdtm,
108 	const int resumeflag,
109 	const int appendflag,
110 	const int deleteflag,
111 	const FTPConfirmResumeDownloadProc resumeProc);
112 
113 int
114 FTPPutOneF(
115 	const FTPCIPtr cip,
116 	const char *const file,
117 	const char *volatile dstfile,
118 	int xtype,
119 	const int fdtouse,
120 	const int appendflag,
121 	const char *volatile tmppfx,
122 	const char *volatile tmpsfx,
123 	const int resumeflag,
124 	const int deleteflag,
125 	const FTPConfirmResumeUploadProc resumeProc,
126 	const time_t batchStartTime,
127 	const time_t origLmtime);
128 
129 int FTPGetOneTarF(const FTPCIPtr cip, const char *file, const char *const dstdir);
130 
131 /* open.c */
132 void FTPResetStatusVariables(const FTPCIPtr cip);
133 void FTPDeallocateHost(const FTPCIPtr cip);
134 int FTPAllocateHost(const FTPCIPtr cip);
135 
136 /* cmds misc */
137 int FTPRmdirRecursive(const FTPCIPtr cip, const char *const dir);
138 int FTPRmdirRecursive2(const FTPCIPtr cip, const char *const dir, const int rmEmptyDirsOnly);
139 void FTPRequestMlsOptions(const FTPCIPtr cip);
140 void RemoteGlobCollapse(const FTPCIPtr, const char *pattern, FTPLineListPtr fileList);
141 int PathContainsIntermediateDotDotSubDir(const char *s);
142 
143 #endif	/* _util_h_ */
144