PageRenderTime 27ms CodeModel.GetById 21ms app.highlight 5ms RepoModel.GetById 0ms app.codeStats 0ms

/ncftp-3.2.5/libncftp/c_modtime.c

#
C | 66 lines | 52 code | 5 blank | 9 comment | 21 complexity | 3f43b67ff507d7155923e31ac6b0026a MD5 | raw file
Possible License(s): AGPL-3.0
 1/* c_modtime.c
 2 *
 3 * Copyright (c) 1996-2005 Mike Gleason, NcFTP Software.
 4 * All rights reserved.
 5 *
 6 */
 7
 8#include "syshdrs.h"
 9#ifdef PRAGMA_HDRSTOP
10#	pragma hdrstop
11#endif
12
13int
14FTPFileModificationTime(const FTPCIPtr cip, const char *const file, time_t *const mdtm)
15{
16	int result;
17	ResponsePtr rp;
18
19	if (cip == NULL)
20		return (kErrBadParameter);
21	if (strcmp(cip->magic, kLibraryMagic))
22		return (kErrBadMagic);
23
24	if ((mdtm == NULL) || (file == NULL))
25		return (kErrBadParameter);
26	*mdtm = kModTimeUnknown;
27
28	if (cip->hasMDTM == kCommandNotAvailable) {
29		cip->errNo = kErrMDTMNotAvailable;
30		result = kErrMDTMNotAvailable;
31	} else {
32		rp = InitResponse();
33		if (rp == NULL) {
34			result = kErrMallocFailed;
35			cip->errNo = kErrMallocFailed;
36			FTPLogError(cip, kDontPerror, "Malloc failed.\n");
37		} else {
38			result = RCmd(cip, rp, "MDTM %s", file);
39			if (result < 0) {
40				DoneWithResponse(cip, rp);
41				return (result);
42			}
43			if (result == 2) {
44				if (strncmp(rp->msg.first->line, "1910", 4) == 0) {
45					/* Year was printed as "19100" rather than
46					 * "2000" ...
47					 */
48					FTPLogError(cip, kDontPerror, "Warning: Server has Y2K Bug in \"MDTM\" command.\n");
49				}
50				*mdtm = UnMDTMDate(rp->msg.first->line);
51				cip->hasMDTM = kCommandAvailable;
52				result = kNoErr;
53			} else if (FTP_UNIMPLEMENTED_CMD(rp->code)) {
54				cip->hasMDTM = kCommandNotAvailable;
55				cip->hasMDTM_set = kCommandNotAvailable;
56				cip->errNo = kErrMDTMNotAvailable;
57				result = kErrMDTMNotAvailable;
58			} else {
59				cip->errNo = kErrMDTMFailed;
60				result = kErrMDTMFailed;
61			}
62			DoneWithResponse(cip, rp);
63		}
64	}
65	return (result);
66}	/* FTPFileModificationTime */