ReactOS 0.4.15-dev-7712-gbbbcd8e
util.c File Reference
#include "syshdrs.h"
Include dependency graph for util.c:

Go to the source code of this file.

Functions

charFTPGetLocalCWD (char *buf, size_t size)
 
charFGets (char *str, size_t size, FILE *fp)
 
struct passwd * GetPwByName (void)
 
charGetPass (const char *const prompt)
 
void GetHomeDir (char *dst, size_t size)
 
void GetUsrName (char *dst, size_t size)
 
void CloseFile (FILE **f)
 
void PrintF (const FTPCIPtr cip, const char *const fmt,...)
 
void Error (const FTPCIPtr cip, const int pError, const char *const fmt,...)
 
static time_t GetUTCOffset (int mon, int mday)
 
time_t UnMDTMDate (char *dstr)
 
int GetSockBufSize (int sockfd, size_t *rsize, size_t *ssize)
 
int SetSockBufSize (int sockfd, size_t rsize, size_t ssize)
 
void Scramble (unsigned char *dst, size_t dsize, unsigned char *src, char *key)
 
void StrRemoveTrailingSlashes (char *dst)
 
int MkDirs (const char *const newdir, int mode1)
 
int FilenameExtensionIndicatesASCII (const char *const pathName, const char *const extnList)
 

Function Documentation

◆ CloseFile()

void CloseFile ( FILE **  f)

Definition at line 327 of file util.c.

328{
329 if (*f != NULL) {
330 if ((*f != stdout) && (*f != stdin) && (*f != stderr))
331 (void) fclose(*f);
332 *f = NULL;
333 }
334} /* CloseFile */
#define NULL
Definition: types.h:112
GLfloat f
Definition: glext.h:7540
#define stdout
Definition: stdio.h:99
#define stderr
Definition: stdio.h:100
#define stdin
Definition: stdio.h:98
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)

Referenced by CloseControlConnection(), FTPRebuildConnectionInfo(), and OpenControlConnection().

◆ Error()

void Error ( const FTPCIPtr  cip,
const int  pError,
const char *const  fmt,
  ... 
)

Definition at line 368 of file util.c.

369{
370 va_list ap;
371 int errnum;
372 size_t len;
373 char buf[256];
374 int endsinperiod;
375 int endsinnewline;
376#ifndef HAVE_STRERROR
377 char errnostr[16];
378#endif
379
380 errnum = errno;
381 va_start(ap, fmt);
382#ifdef HAVE_VSNPRINTF
383 vsnprintf(buf, sizeof(buf) - 1, fmt, ap);
384 buf[sizeof(buf) - 1] = '\0';
385#else
386 (void) vsprintf(buf, fmt, ap);
387#endif
388 va_end(ap);
389
390 if (pError != 0) {
391 len = strlen(buf);
392 endsinperiod = 0;
393 endsinnewline = 0;
394 if (len > 2) {
395 if (buf[len - 1] == '\n') {
396 endsinnewline = 1;
397 buf[len - 1] = '\0';
398 if (buf[len - 2] == '.') {
399 endsinperiod = 1;
400 buf[len - 2] = '\0';
401 }
402 } else if (buf[len - 1] == '.') {
403 endsinperiod = 1;
404 buf[len - 1] = '\0';
405 }
406 }
407#ifdef HAVE_STRERROR
408 (void) STRNCAT(buf, ": ");
409 (void) STRNCAT(buf, strerror(errnum));
410#else
411# ifdef HAVE_SNPRINTF
412 sprintf(errnostr, sizeof(errnostr) - 1, " (errno = %d)", errnum);
413 errnostr[sizeof(errnostr) - 1] = '\0';
414# else
415 sprintf(errnostr, " (errno = %d)", errnum);
416# endif
417 STRNCAT(buf, errnostr);
418#endif
419 if (endsinperiod != 0)
420 (void) STRNCAT(buf, ".");
421 if (endsinnewline != 0)
422 (void) STRNCAT(buf, "\n");
423 }
424
425 if (cip->errLog != NULL) {
426 (void) fprintf(cip->errLog, "%s", buf);
427 (void) fflush(cip->errLog);
428 }
429 if ((cip->debugLog != NULL) && (cip->debugLog != cip->errLog)) {
430 if ((cip->errLog != stderr) || (cip->debugLog != stdout)) {
431 (void) fprintf(cip->debugLog, "%s", buf);
432 (void) fflush(cip->debugLog);
433 }
434 }
435 if (cip->errLogProc != NULL) {
436 (*cip->errLogProc)(cip, buf);
437 }
438 if ((cip->debugLogProc != NULL) && (cip->debugLogProc != cip->errLogProc)) {
439 (*cip->debugLogProc)(cip, buf);
440 }
441} /* Error */
#define STRNCAT(d, s)
Definition: Strn.h:48
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
char * va_list
Definition: acmsvcex.h:78
#define va_end(ap)
Definition: acmsvcex.h:90
#define va_start(ap, A)
Definition: acmsvcex.h:91
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLenum GLsizei len
Definition: glext.h:6722
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
_Check_return_opt_ _CRTIMP int __cdecl fflush(_Inout_opt_ FILE *_File)
int __cdecl vsprintf(char *_Dest, const char *_Format, va_list _Args)
Definition: sprintf.c:733
#define sprintf(buf, format,...)
Definition: sprintf.c:55
const char * strerror(int err)
Definition: compat_str.c:23
#define errno
Definition: errno.h:18
FTPLogProc errLogProc
Definition: ncftp.h:148
FILE * debugLog
Definition: ncftp.h:145
FILE * errLog
Definition: ncftp.h:146
FTPLogProc debugLogProc
Definition: ncftp.h:147
Definition: dsound.c:943
#define vsnprintf
Definition: tif_win32.c:406
void int int ULONGLONG int va_list * ap
Definition: winesup.h:36

◆ FGets()

char * FGets ( char str,
size_t  size,
FILE fp 
)

Definition at line 111 of file util.c.

112{
113 char *cp, *nlptr;
114
115 cp = fgets(str, ((int) size) - 1, fp);
116 if (cp != NULL) {
117 cp[((int) size) - 1] = '\0'; /* ensure terminator */
118 nlptr = cp + strlen(cp) - 1;
119 if (*nlptr == '\n')
120 *nlptr = '\0';
121 } else {
122 memset(str, 0, size);
123 }
124 return cp;
125} /* FGets */
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31
GLsizeiptr size
Definition: glext.h:5919
_Check_return_opt_ _CRTIMP char *__cdecl fgets(_Out_writes_z_(_MaxCount) char *_Buf, _In_ int _MaxCount, _Inout_ FILE *_File)
POINT cp
Definition: magnifier.c:59
const WCHAR * str
#define memset(x, y, z)
Definition: compat.h:39

Referenced by GetBookmark(), GetNextBookmark(), GetPass(), LazyUnixLocalGlob(), OpenBookmarkFile(), PromptForBookmarkName(), PutBookmark(), and RunBookmarkEditor().

◆ FilenameExtensionIndicatesASCII()

int FilenameExtensionIndicatesASCII ( const char *const  pathName,
const char *const  extnList 
)

Definition at line 963 of file util.c.

964{
965 const char *extn;
966 char *cp;
967 int c;
968 char extnPattern[16];
969
970 extn = pathName + strlen(pathName) - 1;
971 forever {
972 if (extn <= pathName)
973 return (0); /* End of pathname, no extension. */
974 c = (int) *--extn;
975 if (IsLocalPathDelim(c))
976 return (0); /* End of filename, no extension. */
977 if (c == '.') {
978 extn += 1;
979 break;
980 }
981 }
982 if (strlen(extn) > (sizeof(extnPattern) - 2 - 1 - 1)) {
983 return (0);
984 }
985#ifdef HAVE_SNPRINTF
986 snprintf(extnPattern, sizeof(extnPattern),
987#else
988 sprintf(extnPattern,
989#endif
990 "|.%s|",
991 extn
992 );
993
994 cp = extnPattern;
995 forever {
996 c = *cp;
997 if (c == '\0')
998 break;
999 if (isupper(c)) {
1000 c = tolower(c);
1001 *cp++ = (char) c;
1002 } else {
1003 cp++;
1004 }
1005 }
1006
1007 /* Extension list is specially formatted, like this:
1008 *
1009 * |ext1|ext2|ext3|...|extN|
1010 *
1011 * I.e, each filename extension is delimited with
1012 * a pipe, and we always begin and end the string
1013 * with a pipe.
1014 */
1015 if (strstr(extnList, extnPattern) != NULL) {
1016 return (1);
1017 }
1018 return (0);
1019} /* FilenameExtensionIndicatesASCII */
char * strstr(char *String1, char *String2)
Definition: utclib.c:653
#define isupper(c)
Definition: acclib.h:71
int tolower(int c)
Definition: utclib.c:902
unsigned char
Definition: typeof.h:29
const GLubyte * c
Definition: glext.h:8905
#define c
Definition: ke_i.h:80
#define forever
Definition: ncftp.h:73
#define IsLocalPathDelim(c)
Definition: ncftp.h:497
#define snprintf
Definition: wintirpc.h:48

Referenced by AutomaticallyUseASCIIModeDependingOnExtension().

◆ FTPGetLocalCWD()

char * FTPGetLocalCWD ( char buf,
size_t  size 
)

Definition at line 29 of file util.c.

30{
31#ifdef HAVE_GETCWD
32 static char *cwdBuf = NULL;
33 static size_t cwdBufSize = 0;
34
35 if (cwdBufSize == 0) {
36 cwdBufSize = (size_t) 128;
37 cwdBuf = (char *) malloc(cwdBufSize);
38 }
39
40 for (errno = 0; ; ) {
41 if (cwdBuf == NULL) {
42 return NULL;
43 }
44
45 if (getcwd(cwdBuf, cwdBufSize) != NULL)
46 break;
47 if (errno != ERANGE) {
48 (void) Strncpy(buf, ".", size);
49 return NULL;
50 }
51 cwdBufSize *= 2;
52 cwdBuf = (char *) Realloc(cwdBuf, cwdBufSize);
53 }
54
55 return (Strncpy(buf, cwdBuf, size));
56#else
57#ifdef HAVE_GETWD
58 static char *cwdBuf = NULL;
59 char *dp;
60
61 /* Due to the way getwd is usually implemented, it's
62 * important to have a buffer large enough to hold the
63 * whole thing. getwd usually starts at the end of the
64 * buffer, and works backwards, returning you a pointer
65 * to the beginning of it when it finishes.
66 */
67 if (size < MAXPATHLEN) {
68 /* Buffer not big enough, so use a temporary one,
69 * and then copy the first 'size' bytes of the
70 * temporary buffer to your 'buf.'
71 */
72 if (cwdBuf == NULL) {
73 cwdBuf = (char *) malloc((size_t) MAXPATHLEN);
74 if (cwdBuf == NULL) {
75 return NULL;
76 }
77 }
78 dp = cwdBuf;
79 } else {
80 /* Buffer is big enough already. */
81 dp = buf;
82 }
83 *dp = '\0';
84 if (getwd(dp) == NULL) {
85 /* getwd() should write the reason why in the buffer then,
86 * according to the man pages.
87 */
88 (void) Strncpy(buf, ".", size);
89 return (NULL);
90 }
91 return (Strncpy(buf, dp, size));
92
93#elif defined(WIN32) || defined(_WINDOWS)
94 if (GetCurrentDirectory((DWORD) size - 1, buf) < 1)
95 return NULL;
96 buf[size - 1] = '\0';
97 return buf;
98#else
99 /* Not a solution, but does anybody not have either of
100 * getcwd or getwd?
101 */
102 --Error--;
103#endif
104#endif
105} /* GetCWD */
char * Strncpy(char *const, const char *const, const size_t)
Definition: Strncpy.c:11
#define ERANGE
Definition: acclib.h:92
BOOL Error
Definition: chkdsk.c:66
#define malloc
Definition: debug_ros.c:4
_Check_return_ _Ret_opt_z_ _CRTIMP char *__cdecl getcwd(_Out_writes_opt_(_SizeInBytes) char *_DstBuf, _In_ int _SizeInBytes)
__kernel_size_t size_t
Definition: linux.h:237
#define getwd
Definition: fake.h:7
unsigned long DWORD
Definition: ntddk_ex.h:95
#define MAXPATHLEN
Definition: ftp_var.h:35
void * Realloc(void *, size_t)
#define GetCurrentDirectory
Definition: winbase.h:3740

Referenced by DoOpen(), LocalChdirCmd(), LocalPwdCmd(), PostInit(), SpoolGetCmd(), SpoolPutCmd(), and SpoolX().

◆ GetHomeDir()

void GetHomeDir ( char dst,
size_t  size 
)

Definition at line 240 of file util.c.

241{
242#if defined(WIN32) || defined(_WINDOWS)
243 const char *homedrive, *homepath;
244
245 homedrive = getenv("HOMEDRIVE");
246 homepath = getenv("HOMEPATH");
247 if ((homedrive != NULL) && (homepath != NULL)) {
248 (void) Strncpy(dst, homedrive, size);
249 (void) Strncat(dst, homepath, size);
250 return;
251 }
252
253// GetSpecialDir(dst, size, CSIDL_PERSONAL /* "My Documents" */);
254// if (dst[0] != '\0')
255// return;
256//
257// dst[0] = '\0';
258// if (GetWindowsDirectory(dst, size - 1) < 1)
259// (void) Strncpy(dst, ".", size);
260// else if (dst[1] == ':') {
261// dst[2] = '\\';
262// dst[3] = '\0';
263// }
264#else
265 const char *cp;
266 struct passwd *pw;
267
268 pw = NULL;
269#if defined(USE_GETPWUID)
270 /* Try to use getpwuid(), but if we have to, fall back to getpwnam(). */
271 if ((pw = getpwuid(getuid())) == NULL)
272 pw = GetPwByName(); /* Oh well, try getpwnam() then. */
273#else
274 /* Try to use getpwnam(), but if we have to, fall back to getpwuid(). */
275 if ((pw = GetPwByName()) == NULL)
276 pw = getpwuid(getuid()); /* Try getpwnam() then. */
277#endif
278 if (pw != NULL)
279 cp = pw->pw_dir;
280 else if ((cp = (const char *) getenv("LOGNAME")) == NULL)
281 cp = ".";
282 (void) Strncpy(dst, cp, size);
283#endif
284} /* GetHomeDir */
char * Strncat(char *const, const char *const, const size_t)
Definition: Strncat.c:13
uid_t getuid()
Definition: uid.c:27
GLenum GLenum dst
Definition: glext.h:6340
_Check_return_ char *__cdecl getenv(_In_z_ const char *_VarName)
struct passwd * GetPwByName(void)
Definition: util.c:165

Referenced by ExpandTilde().

◆ GetPass()

char * GetPass ( const char *const  prompt)

Definition at line 186 of file util.c.

187{
188#ifdef HAVE_GETPASS
189 return getpass(prompt);
190#elif defined(_CONSOLE) && (defined(WIN32) || defined(_WINDOWS))
191 static char pwbuf[128];
192 char *dst, *dlim;
193 int c;
194
195 (void) memset(pwbuf, 0, sizeof(pwbuf));
196 if (! _isatty(_fileno(stdout)))
197 return (pwbuf);
198 (void) fputs(prompt, stdout);
199 (void) fflush(stdout);
200
201 for (dst = pwbuf, dlim = dst + sizeof(pwbuf) - 1;;) {
202 c = _getch();
203 if ((c == 0) || (c == 0xe0)) {
204 /* The key is a function or arrow key; read and discard. */
205 (void) _getch();
206 }
207 if ((c == '\r') || (c == '\n'))
208 break;
209 if (dst < dlim)
210 *dst++ = c;
211 }
212 *dst = '\0';
213
214 (void) fflush(stdout);
215 (void) fflush(stdin);
216 return (pwbuf);
217#else
218 static char pwbuf[128];
219
220 (void) memset(pwbuf, 0, sizeof(pwbuf));
221#if defined(WIN32) || defined(_WINDOWS)
222 if (! _isatty(_fileno(stdout)))
223#else
224 if (! isatty(1))
225#endif
226 return (pwbuf);
227 (void) fputs(prompt, stdout);
228 (void) fflush(stdout);
229 (void) FGets(pwbuf, sizeof(pwbuf), stdin);
230 (void) fflush(stdout);
231 (void) fflush(stdin);
232 return (pwbuf);
233#endif
234} /* GetPass */
#define isatty
Definition: acwin.h:103
char * getpass(const char *prompt)
Definition: fake.c:231
_Check_return_ _CRTIMP int __cdecl _fileno(_In_ FILE *_File)
_Check_return_opt_ _CRTIMP int __cdecl fputs(_In_z_ const char *_Str, _Inout_ FILE *_File)
char * FGets(char *str, size_t size, FILE *fp)
Definition: util.c:111
_Check_return_ _CRTIMP int __cdecl _isatty(_In_ int _FileHandle)
int _getch()
Definition: getch.c:16

Referenced by DECLARE_INTERFACE_().

◆ GetPwByName()

struct passwd * GetPwByName ( void  )

Definition at line 165 of file util.c.

166{
167 char *cp;
168 struct passwd *pw;
169
170 cp = getlogin();
171 if (cp == NULL) {
172 cp = (char *) getenv("LOGNAME");
173 if (cp == NULL)
174 cp = (char *) getenv("USER");
175 }
176 pw = NULL;
177 if (cp != NULL)
178 pw = getpwnam(cp);
179 return (pw);
180} /* GetPwByName */
char * getlogin(void)

Referenced by GetHomeDir(), and GetUsrName().

◆ GetSockBufSize()

int GetSockBufSize ( int  sockfd,
size_t rsize,
size_t ssize 
)

Definition at line 534 of file util.c.

535{
536#ifdef SO_SNDBUF
537 int rc = -1;
538 int opt;
539 int optsize;
540
541 if (ssize != NULL) {
542 opt = 0;
543 optsize = sizeof(opt);
544 rc = getsockopt(sockfd, SOL_SOCKET, SO_SNDBUF, (char *) &opt, &optsize);
545 if (rc == 0)
546 *ssize = (size_t) opt;
547 else
548 *ssize = 0;
549 }
550 if (rsize != NULL) {
551 opt = 0;
552 optsize = sizeof(opt);
553 rc = getsockopt(sockfd, SOL_SOCKET, SO_RCVBUF, (char *) &opt, &optsize);
554 if (rc == 0)
555 *rsize = (size_t) opt;
556 else
557 *rsize = 0;
558 }
559 return (rc);
560#else
561 if (ssize != NULL)
562 *ssize = 0;
563 if (rsize != NULL)
564 *rsize = 0;
565 return (-1);
566#endif
567} /* GetSockBufSize */
INT WSAAPI getsockopt(IN SOCKET s, IN INT level, IN INT optname, OUT CHAR FAR *optval, IN OUT INT FAR *optlen)
Definition: sockctrl.c:271
#define SO_RCVBUF
Definition: winsock.h:189
#define SOL_SOCKET
Definition: winsock.h:398
#define SO_SNDBUF
Definition: winsock.h:188

◆ GetUsrName()

void GetUsrName ( char dst,
size_t  size 
)

Definition at line 290 of file util.c.

291{
292#if defined(WIN32) || defined(_WINDOWS)
293 DWORD size1;
294
295 size1 = size - 1;
296 if (! GetUserName(dst, &size1))
297 (void) strncpy(dst, "unknown", size);
298 dst[size - 1] = '\0';
299#else
300 const char *cp;
301 struct passwd *pw;
302
303 pw = NULL;
304#ifdef USE_GETPWUID
305 /* Try to use getpwuid(), but if we have to, fall back to getpwnam(). */
306 if ((pw = getpwuid(getuid())) == NULL)
307 pw = GetPwByName(); /* Oh well, try getpwnam() then. */
308#else
309 /* Try to use getpwnam(), but if we have to, fall back to getpwuid(). */
310 if ((pw = GetPwByName()) == NULL)
311 pw = getpwuid(getuid()); /* Try getpwnam() then. */
312#endif
313 if (pw != NULL)
314 cp = pw->pw_name;
315 else if ((cp = (const char *) getenv("LOGNAME")) == NULL)
316 cp = "UNKNOWN";
317 (void) Strncpy(dst, cp, size);
318#endif
319} /* GetUserName */
char * strncpy(char *DstString, const char *SrcString, ACPI_SIZE Count)
Definition: utclib.c:427
#define GetUserName
Definition: winbase.h:3786

Referenced by FTPInitializeAnonPassword().

◆ GetUTCOffset()

static time_t GetUTCOffset ( int  mon,
int  mday 
)
static

Definition at line 449 of file util.c.

450{
451 struct tm local_tm, utc_tm, *utc_tmptr;
452 time_t local_t, utc_t, utcOffset;
453
454 ZERO(local_tm);
455 ZERO(utc_tm);
456 utcOffset = 0;
457
458 local_tm.tm_year = 94; /* Doesn't really matter. */
459 local_tm.tm_mon = mon;
460 local_tm.tm_mday = mday;
461 local_tm.tm_hour = 12;
462 local_tm.tm_isdst = -1;
463 local_t = mktime(&local_tm);
464
465 if (local_t != (time_t) -1) {
466 utc_tmptr = gmtime(&local_t);
467 utc_tm.tm_year = utc_tmptr->tm_year;
468 utc_tm.tm_mon = utc_tmptr->tm_mon;
469 utc_tm.tm_mday = utc_tmptr->tm_mday;
470 utc_tm.tm_hour = utc_tmptr->tm_hour;
471 utc_tm.tm_isdst = -1;
472 utc_t = mktime(&utc_tm);
473
474 if (utc_t != (time_t) -1)
475 utcOffset = (local_t - utc_t);
476 }
477 return (utcOffset);
478} /* GetUTCOffset */
#define ZERO
Definition: arc.cc:50
__kernel_time_t time_t
Definition: linux.h:252
_CRTIMP struct tm *__cdecl gmtime(const time_t *_Time)
Definition: time.h:415
_CRTIMP time_t __cdecl mktime(struct tm *_Tm)
Definition: time.h:418
Definition: time.h:68
int tm_mon
Definition: time.h:73
int tm_year
Definition: time.h:74
int tm_hour
Definition: time.h:71
int tm_mday
Definition: time.h:72

Referenced by UnMDTMDate().

◆ MkDirs()

int MkDirs ( const char *const  newdir,
int  mode1 
)

Definition at line 785 of file util.c.

786{
787 char s[512];
788 int rc;
789 char *cp, *sl;
790#if defined(WIN32) || defined(_WINDOWS)
791 struct _stat st;
792 char *share;
793#else
794 struct Stat st;
795 mode_t mode = (mode_t) mode1;
796#endif
797
798#if defined(WIN32) || defined(_WINDOWS)
799 if ((isalpha(newdir[0])) && (newdir[1] == ':')) {
800 if (! IsLocalPathDelim(newdir[2])) {
801 /* Special case "c:blah", and errout.
802 * "c:\blah" must be used or _access GPFs.
803 */
804 errno = EINVAL;
805 return (-1);
806 } else if (newdir[3] == '\0') {
807 /* Special case root directory, which cannot be made. */
808 return (0);
809 }
810 } else if (IsUNCPrefixed(newdir)) {
811 share = StrFindLocalPathDelim(newdir + 2);
812 if ((share == NULL) || (StrFindLocalPathDelim(share + 1) == NULL))
813 return (-1);
814 }
815
816 if (_access(newdir, 00) == 0) {
817 if (_stat(newdir, &st) < 0)
818 return (-1);
819 if (! S_ISDIR(st.st_mode)) {
820 errno = ENOTDIR;
821 return (-1);
822 }
823 return 0;
824 }
825#else
826 if (access(newdir, F_OK) == 0) {
827 if (Stat(newdir, &st) < 0)
828 return (-1);
829 if (! S_ISDIR(st.st_mode)) {
830 errno = ENOTDIR;
831 return (-1);
832 }
833 return 0;
834 }
835#endif
836
837 (void) strncpy(s, newdir, sizeof(s));
838 if (s[sizeof(s) - 1] != '\0') {
839#ifdef ENAMETOOLONG
841#else
842 errno = EINVAL;
843 return (-1);
844#endif
845 }
846
848 if (cp == NULL) {
849#if defined(WIN32) || defined(_WINDOWS)
850 if (! CreateDirectory(newdir, (LPSECURITY_ATTRIBUTES) 0))
851 return (-1);
852 return (0);
853#else
854 rc = mkdir(newdir, mode);
855 return (rc);
856#endif
857 } else if (cp[1] == '\0') {
858 /* Remove trailing slashes from path. */
859 --cp;
860 while (cp > s) {
861 if (! IsLocalPathDelim(*cp))
862 break;
863 --cp;
864 }
865 cp[1] = '\0';
867 if (cp == NULL) {
868#if defined(WIN32) || defined(_WINDOWS)
870 return (-1);
871#else
872 rc = mkdir(s, mode);
873 return (rc);
874#endif
875 }
876 }
877
878 /* Find the deepest directory in this
879 * path that already exists. When
880 * we do, we want to have the 's'
881 * string as it was originally, but
882 * with 'cp' pointing to the first
883 * slash in the path that starts the
884 * part that does not exist.
885 */
886 sl = NULL;
887 for (;;) {
888 *cp = '\0';
889#if defined(WIN32) || defined(_WINDOWS)
890 rc = _access(s, 00);
891#else
892 rc = access(s, F_OK);
893#endif
894 if (sl != NULL)
895 *sl = LOCAL_PATH_DELIM;
896 if (rc == 0) {
898 break;
899 }
900 sl = cp;
902 if (cp == NULL) {
903 /* We do not have any more
904 * slashes, so none of the
905 * new directory's components
906 * existed before, so we will
907 * have to make everything
908 * starting at the first node.
909 */
910 if (sl != NULL)
911 *sl = LOCAL_PATH_DELIM;
912
913 /* We refer to cp + 1 below,
914 * so this is why we can
915 * set "cp" to point to the
916 * byte before the array starts.
917 */
918 cp = s - 1;
919 break;
920 }
921 }
922
923 for (;;) {
924 /* Extend the path we have to
925 * include the next component
926 * to make.
927 */
928 sl = StrFindLocalPathDelim(cp + 1);
929 if (sl == s) {
930 /* If the next slash is pointing
931 * to the start of the string, then
932 * the path is an absolute path and
933 * we don't need to make the root node,
934 * and besides the next mkdir would
935 * try an empty string.
936 */
937 ++cp;
938 sl = StrFindLocalPathDelim(cp + 1);
939 }
940 if (sl != NULL) {
941 *sl = '\0';
942 }
943#if defined(WIN32) || defined(_WINDOWS)
945 return (-1);
946#else
947 rc = mkdir(s, mode);
948 if (rc < 0)
949 return rc;
950#endif
951 if (sl == NULL)
952 break;
953 *sl = LOCAL_PATH_DELIM;
954 cp = sl;
955 }
956 return (0);
957} /* MkDirs */
#define EINVAL
Definition: acclib.h:90
#define isalpha(c)
Definition: acclib.h:74
#define mkdir
Definition: acwin.h:101
#define S_ISDIR(mode)
Definition: various.h:18
#define ENOTDIR
Definition: errno.h:26
__kernel_mode_t mode_t
Definition: linux.h:199
#define IsUNCPrefixed(s)
Definition: getline.c:59
GLdouble s
Definition: gl.h:2039
GLenum mode
Definition: glext.h:6217
GLuint GLint GLboolean GLint GLenum access
Definition: glext.h:7866
#define Stat
Definition: syshdrs.h:78
#define F_OK
Definition: util.h:52
#define LOCAL_PATH_DELIM
Definition: ncftp.h:492
#define StrRFindLocalPathDelim(a)
Definition: ncftp.h:495
#define StrFindLocalPathDelim(a)
Definition: ncftp.h:494
#define ENAMETOOLONG
Definition: errno.h:55
_Check_return_ _CRTIMP int __cdecl _access(_In_z_ const char *_Filename, _In_ int _AccessMode)
Definition: stat.h:40
#define CreateDirectory
Definition: winbase.h:3681

Referenced by FTPGetFiles3(), InitOurDirectory(), LocalMkdirCmd(), and MkSpoolDir().

◆ PrintF()

void PrintF ( const FTPCIPtr  cip,
const char *const  fmt,
  ... 
)

Definition at line 340 of file util.c.

341{
342 va_list ap;
343 char buf[256];
344
345 va_start(ap, fmt);
346 if (cip->debugLog != NULL) {
347 (void) vfprintf(cip->debugLog, fmt, ap);
348 (void) fflush(cip->debugLog);
349 }
350 if (cip->debugLogProc != NULL) {
351#ifdef HAVE_VSNPRINTF
352 (void) vsnprintf(buf, sizeof(buf) - 1, fmt, ap);
353 buf[sizeof(buf) - 1] = '\0';
354#else
355 (void) vsprintf(buf, fmt, ap);
356#endif
357 (*cip->debugLogProc)(cip, buf);
358 }
359 va_end(ap);
360} /* PrintF */
_Check_return_opt_ _CRTIMP int __cdecl vfprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format, va_list _ArgList)

Referenced by FTPAbortDataTransfer(), FTPGetFiles3(), FTPLoginHost(), FTPOpenHost(), FTPOpenHostNoLogin(), FTPPutFiles3(), FTPRemoteGlob(), LazyUnixLocalGlob(), OpenControlConnection(), PrintResponse(), SendCommand(), and TraceResponse().

◆ Scramble()

void Scramble ( unsigned char dst,
size_t  dsize,
unsigned char src,
char key 
)

Definition at line 607 of file util.c.

608{
609 int i;
610 unsigned int ch;
611 unsigned char *k2;
612 size_t keyLen;
613
614 keyLen = strlen(key);
615 k2 = (unsigned char *) key;
616 for (i=0; i < (int) dsize - 1; i++) {
617 ch = src[i];
618 if (ch == 0)
619 break;
620 dst[i] = (unsigned char) (ch ^ (int) (k2[i % (int) keyLen]));
621 }
622 dst[i] = '\0';
623} /* Scramble */
GLenum src
Definition: glext.h:6340
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
Definition: copy.c:22

◆ SetSockBufSize()

int SetSockBufSize ( int  sockfd,
size_t  rsize,
size_t  ssize 
)

Definition at line 572 of file util.c.

573{
574#ifdef SO_SNDBUF
575 int rc = -1;
576 int opt;
577 int optsize;
578
579#ifdef TCP_RFC1323
580 /* This is an AIX-specific socket option to do RFC1323 large windows */
581 if (ssize > 0 || rsize > 0) {
582 opt = 1;
583 optsize = sizeof(opt);
584 rc = setsockopt(sockfd, IPPROTO_TCP, TCP_RFC1323, &opt, optsize);
585 }
586#endif
587
588 if (ssize > 0) {
589 opt = (int) ssize;
590 optsize = sizeof(opt);
591 rc = setsockopt(sockfd, SOL_SOCKET, SO_SNDBUF, (char *) &opt, optsize);
592 }
593 if (rsize > 0) {
594 opt = (int) rsize;
595 optsize = sizeof(opt);
596 rc = setsockopt(sockfd, SOL_SOCKET, SO_RCVBUF, (char *) &opt, optsize);
597 }
598 return (rc);
599#else
600 return (-1);
601#endif
602} /* SetSockBufSize */
#define IPPROTO_TCP
Definition: ip.h:196
INT WSAAPI setsockopt(IN SOCKET s, IN INT level, IN INT optname, IN CONST CHAR FAR *optval, IN INT optlen)
Definition: sockctrl.c:421

Referenced by OpenControlConnection(), and OpenDataConnection().

◆ StrRemoveTrailingSlashes()

void StrRemoveTrailingSlashes ( char dst)

Definition at line 768 of file util.c.

769{
770 char *cp;
771
772 cp = strrchr(dst, '/');
773 if ((cp == NULL) || (cp[1] != '\0'))
774 return;
775
776 /* Note: Do not destroy a path of "/" */
777 while ((cp > dst) && (*cp == '/'))
778 *cp-- = '\0';
779} /* StrRemoveTrailingSlashes */
_Check_return_ _CRTIMP _CONST_RETURN char *__cdecl strrchr(_In_z_ const char *_Str, _In_ int _Ch)

Referenced by FTPGetFiles3(), GetCmd(), PutCmd(), SpoolGetCmd(), and SpoolPutCmd().

◆ UnMDTMDate()

time_t UnMDTMDate ( char dstr)

Definition at line 486 of file util.c.

487{
488#ifndef HAVE_MKTIME
489 return (kModTimeUnknown);
490#else
491 struct tm ut, *t;
492 time_t mt, now;
494
495 if (strncmp(dstr, "19100", 5) == 0) {
496 /* Server Y2K bug! */
497 return (result);
498 }
499
500 (void) time(&now);
501 t = localtime(&now);
502
503 /* Copy the whole structure of the 'tm' pointed to by t, so it will
504 * also set all fields we don't specify explicitly to be the same as
505 * they were in t. That way we copy non-standard fields such as
506 * tm_gmtoff, if it exists or not.
507 */
508 ut = *t;
509
510 /* The time we get back from the server is (should be) in UTC. */
511 if (sscanf(dstr, "%04d%02d%02d%02d%02d%02d",
512 &ut.tm_year,
513 &ut.tm_mon,
514 &ut.tm_mday,
515 &ut.tm_hour,
516 &ut.tm_min,
517 &ut.tm_sec) == 6)
518 {
519 --ut.tm_mon;
520 ut.tm_year -= 1900;
521 mt = mktime(&ut);
522 if (mt != (time_t) -1) {
523 mt += GetUTCOffset(ut.tm_mon, ut.tm_mday);
524 result = (time_t) mt;
525 }
526 }
527 return result;
528#endif /* HAVE_MKTIME */
529} /* UnMDTMDate */
int strncmp(const char *String1, const char *String2, ACPI_SIZE Count)
Definition: utclib.c:534
time_t now
Definition: finger.c:65
GLdouble GLdouble t
Definition: gl.h:2047
GLuint64EXT * result
Definition: glext.h:11304
_Check_return_ _CRTIMP int __cdecl sscanf(_In_z_ const char *_Src, _In_z_ _Scanf_format_string_ const char *_Format,...)
__u16 time
Definition: mkdosfs.c:8
static time_t GetUTCOffset(int mon, int mday)
Definition: util.c:449
#define kModTimeUnknown
Definition: ncftp.h:377
_CRTIMP struct tm *__cdecl localtime(const time_t *_Time)
Definition: time.h:416

Referenced by FTPFileModificationTime(), and UnMlsT().