home *** CD-ROM | disk | FTP | other *** search
/ ftp.ncftp.com / ftp.ncftp.com.zip / ftp.ncftp.com / ncftp / older_versions / ncftp-3.2.2-src.tar.bz2 / ncftp-3.2.2-src.tar / ncftp-3.2.2 / libncftp / c_filetype.c < prev    next >
C/C++ Source or Header  |  2005-01-01  |  2KB  |  119 lines

  1. /* c_filetype.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.  
  13. int
  14. FTPFileType(const FTPCIPtr cip, const char *const file, int *const ftype)
  15. {
  16.     int result;
  17.     MLstItem mlsInfo;
  18.  
  19.     if (cip == NULL)
  20.         return (kErrBadParameter);
  21.     if (strcmp(cip->magic, kLibraryMagic))
  22.         return (kErrBadMagic);
  23.  
  24.     if ((file == NULL) || (file[0] == '\0')) {
  25.         cip->errNo = kErrBadParameter;
  26.         return (kErrBadParameter);
  27.     }
  28.  
  29.     if (ftype == NULL) {
  30.         cip->errNo = kErrBadParameter;
  31.         return (kErrBadParameter);
  32.     }
  33.  
  34.     *ftype = 0;
  35.     result = FTPMListOneFile(cip, file, &mlsInfo);
  36.     if (result == kNoErr) {
  37.         *ftype = mlsInfo.ftype;
  38.         return (kNoErr);
  39.     }
  40.  
  41.     /* Preserve old working directory. */
  42.     (void) FTPGetCWD(cip, cip->buf, cip->bufSize);
  43.  
  44.     result = FTPChdir(cip, file);
  45.     if (result == kNoErr) {
  46.         *ftype = 'd';
  47.         /* Yes it was a directory, now go back to
  48.          * where we were.
  49.          */
  50.         (void) FTPChdir(cip, cip->buf);
  51.  
  52.         /* Note:  This improperly assumes that we
  53.          * will be able to chdir back, which is
  54.          * not guaranteed.
  55.          */
  56.         return (kNoErr);
  57.     }
  58.  
  59.     result = FTPFileExists2(cip, file, 1, 1, 0, 1, 1);
  60.     if (result != kErrNoSuchFileOrDirectory)
  61.         result = kErrFileExistsButCannotDetermineType;
  62.  
  63.     return (result);
  64. }    /* FTPFileType */
  65.  
  66.  
  67.  
  68.  
  69. int
  70. FTPIsDir(const FTPCIPtr cip, const char *const dir)
  71. {
  72.     int result, ftype;
  73.  
  74.     if (cip == NULL)
  75.         return (kErrBadParameter);
  76.     if (strcmp(cip->magic, kLibraryMagic))
  77.         return (kErrBadMagic);
  78.  
  79.     if ((dir == NULL) || (dir[0] == '\0')) {
  80.         cip->errNo = kErrInvalidDirParam;
  81.         return (kErrInvalidDirParam);
  82.     }
  83.  
  84.     result = FTPFileType(cip, dir, &ftype);
  85.     if ((result == kNoErr) || (result == kErrFileExistsButCannotDetermineType)) {
  86.         result = 0;
  87.         if (ftype == 'd')
  88.             result = 1;
  89.     }
  90.     return (result);
  91. }    /* FTPIsDir */
  92.  
  93.  
  94.  
  95.  
  96. int
  97. FTPIsRegularFile(const FTPCIPtr cip, const char *const file)
  98. {
  99.     int result, ftype;
  100.  
  101.     if (cip == NULL)
  102.         return (kErrBadParameter);
  103.     if (strcmp(cip->magic, kLibraryMagic))
  104.         return (kErrBadMagic);
  105.  
  106.     if ((file == NULL) || (file[0] == '\0')) {
  107.         cip->errNo = kErrBadParameter;
  108.         return (kErrBadParameter);
  109.     }
  110.  
  111.     result = FTPFileType(cip, file, &ftype);
  112.     if ((result == kNoErr) || (result == kErrFileExistsButCannotDetermineType)) {
  113.         result = 1;
  114.         if (ftype == 'd')
  115.             result = 0;
  116.     }
  117.     return (result);
  118. }    /* FTPIsRegularFile */
  119.