PageRenderTime 38ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 1ms

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