1 /*@-type@*/ /* LCL: function typedefs */
8 #include <rpmio_internal.h>
17 extern int _ftp_debug;
21 extern int _rpmio_debug;
24 /* =============================================================== */
25 static int ftpMkdir(const char * path, /*@unused@*/ mode_t mode)
26 /*@globals fileSystem @*/
27 /*@modifies fileSystem @*/
30 if ((rc = ftpCmd("MKD", path, NULL)) != 0)
34 sprintf(buf, " 0%o", mode);
35 (void) ftpCmd("SITE CHMOD", path, buf);
41 static int ftpChdir(const char * path)
42 /*@globals fileSystem @*/
43 /*@modifies fileSystem @*/
45 return ftpCmd("CWD", path, NULL);
48 static int ftpRmdir(const char * path)
49 /*@globals fileSystem @*/
50 /*@modifies fileSystem @*/
52 return ftpCmd("RMD", path, NULL);
55 static int ftpRename(const char * oldpath, const char * newpath)
56 /*@globals fileSystem @*/
57 /*@modifies fileSystem @*/
60 if ((rc = ftpCmd("RNFR", oldpath, NULL)) != 0)
62 return ftpCmd("RNTO", newpath, NULL);
65 static int ftpUnlink(const char * path)
66 /*@globals fileSystem @*/
67 /*@modifies fileSystem @*/
69 return ftpCmd("DELE", path, NULL);
72 /* =============================================================== */
73 /* XXX rebuilddb.c: analogues to mkdir(2)/rmdir(2). */
74 int Mkdir (const char * path, mode_t mode)
77 int ut = urlPath(path, &lpath);
81 return ftpMkdir(path, mode);
82 /*@notreached@*/ break;
83 case URL_IS_HTTP: /* XXX WRONG WRONG WRONG */
92 /*@notreached@*/ break;
94 return mkdir(path, mode);
97 int Chdir (const char * path)
100 int ut = urlPath(path, &lpath);
104 return ftpChdir(path);
105 /*@notreached@*/ break;
106 case URL_IS_HTTP: /* XXX WRONG WRONG WRONG */
115 /*@notreached@*/ break;
120 int Rmdir (const char * path)
123 int ut = urlPath(path, &lpath);
127 return ftpRmdir(path);
128 /*@notreached@*/ break;
129 case URL_IS_HTTP: /* XXX WRONG WRONG WRONG */
138 /*@notreached@*/ break;
143 /* XXX rpmdb.c: analogue to rename(2). */
145 int Rename (const char * oldpath, const char * newpath)
147 const char *oe = NULL;
148 const char *ne = NULL;
151 /* XXX lib/install.c used to rely on this behavior. */
152 if (!strcmp(oldpath, newpath)) return 0;
154 oldut = urlPath(oldpath, &oe);
156 case URL_IS_FTP: /* XXX WRONG WRONG WRONG */
157 case URL_IS_HTTP: /* XXX WRONG WRONG WRONG */
164 /*@notreached@*/ break;
167 newut = urlPath(newpath, &ne);
171 fprintf(stderr, "*** rename old %*s new %*s\n", (int)(oe - oldpath), oldpath, (int)(ne - newpath), newpath);
172 if (!(oldut == newut && oe && ne && (oe - oldpath) == (ne - newpath) &&
173 !xstrncasecmp(oldpath, newpath, (oe - oldpath))))
175 return ftpRename(oldpath, newpath);
176 /*@notreached@*/ break;
177 case URL_IS_HTTP: /* XXX WRONG WRONG WRONG */
187 /*@notreached@*/ break;
189 return rename(oldpath, newpath);
192 int Link (const char * oldpath, const char * newpath)
194 const char *oe = NULL;
195 const char *ne = NULL;
198 oldut = urlPath(oldpath, &oe);
200 case URL_IS_FTP: /* XXX WRONG WRONG WRONG */
201 case URL_IS_HTTP: /* XXX WRONG WRONG WRONG */
208 /*@notreached@*/ break;
211 newut = urlPath(newpath, &ne);
213 case URL_IS_HTTP: /* XXX WRONG WRONG WRONG */
214 case URL_IS_FTP: /* XXX WRONG WRONG WRONG */
217 fprintf(stderr, "*** link old %*s new %*s\n", (int)(oe - oldpath), oldpath, (int)(ne - newpath), newpath);
218 if (!(oldut == newut && oe && ne && (oe - oldpath) == (ne - newpath) &&
219 !xstrncasecmp(oldpath, newpath, (oe - oldpath))))
229 /*@notreached@*/ break;
231 return link(oldpath, newpath);
234 /* XXX build/build.c: analogue to unlink(2). */
236 int Unlink(const char * path) {
238 int ut = urlPath(path, &lpath);
242 return ftpUnlink(path);
243 /*@notreached@*/ break;
244 case URL_IS_HTTP: /* XXX WRONG WRONG WRONG */
253 /*@notreached@*/ break;
258 /* XXX swiped from mc-4.5.39-pre9 vfs/ftpfs.c */
260 #define g_strdup xstrdup
264 * FIXME: this is broken. It depends on mc not crossing border on month!
267 static int current_mday;
269 static int current_mon;
271 static int current_year;
273 /* Following stuff (parse_ls_lga) is used by ftpfs and extfs */
277 static char *columns [MAXCOLS]; /* Points to the string in column n */
279 static int column_ptr [MAXCOLS]; /* Index from 0 to the starting positions of the columns */
282 vfs_split_text (char *p)
283 /*@globals columns, column_ptr @*/
284 /*@modifies *p, columns, column_ptr @*/
290 for (numcols = 0; *p && numcols < MAXCOLS; numcols++){
291 while (*p == ' ' || *p == '\r' || *p == '\n'){
295 columns [numcols] = p;
296 column_ptr [numcols] = p - original;
297 while (*p && *p != ' ' && *p != '\r' && *p != '\n')
307 if (!columns [idx] || columns [idx][0] < '0' || columns [idx][0] > '9')
313 is_dos_date(/*@null@*/ const char *str)
316 if (str != NULL && strlen(str) == 8 &&
317 str[2] == str[5] && strchr("\\-/", (int)str[2]) != NULL)
323 is_week (/*@null@*/ const char * str, /*@out@*/ struct tm * tim)
326 /*@observer@*/ static const char * week = "SunMonTueWedThuFriSat";
329 /*@-observertrans -mayaliasunique@*/
330 if (str != NULL && (pos=strstr(week, str)) != NULL) {
331 /*@=observertrans =mayaliasunique@*/
333 tim->tm_wday = (pos - week)/3;
340 is_month (/*@null@*/ const char * str, /*@out@*/ struct tm * tim)
343 /*@observer@*/ static const char * month = "JanFebMarAprMayJunJulAugSepOctNovDec";
346 /*@-observertrans -mayaliasunique@*/
347 if (str != NULL && (pos = strstr(month, str)) != NULL) {
348 /*@=observertrans -mayaliasunique@*/
350 tim->tm_mon = (pos - month)/3;
357 is_time (/*@null@*/ const char * str, /*@out@*/ struct tm * tim)
360 const char * p, * p2;
362 if (str != NULL && (p = strchr(str, ':')) && (p2 = strrchr(str, ':'))) {
364 if (sscanf (str, "%2d:%2d:%2d", &tim->tm_hour, &tim->tm_min, &tim->tm_sec) != 3)
367 if (sscanf (str, "%2d:%2d", &tim->tm_hour, &tim->tm_min) != 2)
376 static int is_year(/*@null@*/ const char * str, /*@out@*/ struct tm * tim)
387 if (strlen(str) != 4)
390 if (sscanf(str, "%ld", &year) != 1)
393 if (year < 1900 || year > 3000)
396 tim->tm_year = (int) (year - 1900);
402 * FIXME: this is broken. Consider following entry:
403 * -rwx------ 1 root root 1 Aug 31 10:04 2904 1234
404 * where "2904 1234" is filename. Well, this code decodes it as year :-(.
408 vfs_parse_filetype (char c)
412 case 'd': return S_IFDIR;
413 case 'b': return S_IFBLK;
414 case 'c': return S_IFCHR;
415 case 'l': return S_IFLNK;
417 #ifdef IS_IFSOCK /* And if not, we fall through to IFIFO, which is pretty close */
420 case 'p': return S_IFIFO;
421 case 'm': case 'n': /* Don't know what these are :-) */
422 case '-': case '?': return S_IFREG;
427 static int vfs_parse_filemode (const char *p)
429 { /* converts rw-rw-rw- into 0666 */
432 case 'r': res |= 0400; break;
437 case 'w': res |= 0200; break;
442 case 'x': res |= 0100; break;
443 case 's': res |= 0100 | S_ISUID; break;
444 case 'S': res |= S_ISUID; break;
449 case 'r': res |= 0040; break;
454 case 'w': res |= 0020; break;
459 case 'x': res |= 0010; break;
460 case 's': res |= 0010 | S_ISGID; break;
461 case 'l': /* Solaris produces these */
462 case 'S': res |= S_ISGID; break;
467 case 'r': res |= 0004; break;
472 case 'w': res |= 0002; break;
477 case 'x': res |= 0001; break;
478 case 't': res |= 0001 | S_ISVTX; break;
479 case 'T': res |= S_ISVTX; break;
486 static int vfs_parse_filedate(int idx, /*@out@*/ time_t *t)
488 { /* This thing parses from idx in columns[] array */
495 /* Let's setup default time values */
496 tim.tm_year = current_year;
497 tim.tm_mon = current_mon;
498 tim.tm_mday = current_mday;
502 tim.tm_isdst = -1; /* Let mktime() try to guess correct dst offset */
506 /* We eat weekday name in case of extfs */
511 if(is_month(p, &tim)){
512 /* And we expect, it followed by day number */
514 tim.tm_mday = (int)atol (columns [idx++]);
516 return 0; /* No day */
519 /* We usually expect:
522 But in case of extfs we allow these date formats:
525 Wek Mon DD hh:mm:ss YYYY
527 where Mon is Jan-Dec, DD, MM, YY two digit day, month, year,
528 YYYY four digit year, hh, mm, ss two digit hour, minute or second. */
530 /* Here just this special case with MM-DD-YY */
536 memset(d, 0, sizeof(d));
537 if (sscanf(p, "%2d-%2d-%2d", &d[0], &d[1], &d[2]) == 3){
544 /* Hmm... maybe, next time :)*/
546 /* At last, MM-DD-YY */
547 d[0]--; /* Months are zerobased */
557 return 0; /* sscanf failed */
559 return 0; /* unsupported format */
562 /* Here we expect to find time and/or year */
565 if(is_time(columns[idx], &tim) || (got_year = is_year(columns[idx], &tim))) {
568 /* This is a special case for ctime() or Mon DD YYYY hh:mm */
570 ((got_year = is_year(columns[idx], &tim)) || is_time(columns[idx], &tim)))
571 idx++; /* time & year or reverse */
572 } /* only time or date */
575 return 0; /* Nor time or date */
578 * If the date is less than 6 months in the past, it is shown without year
579 * other dates in the past or future are shown with year but without time
580 * This does not check for years before 1900 ... I don't know, how
581 * to represent them at all
584 current_mon < 6 && current_mon < tim.tm_mon &&
585 tim.tm_mon - current_mon >= 6)
589 if ((*t = mktime(&tim)) < 0)
595 vfs_parse_ls_lga (char * p, /*@out@*/ struct stat * st,
596 /*@out@*/ const char ** filename,
597 /*@out@*/ const char ** linkname)
598 /*@modifies *p, *st, *filename, *linkname @*/
600 int idx, idx2, num_cols;
604 if (strncmp (p, "total", 5) == 0)
607 p_copy = g_strdup(p);
608 /* XXX FIXME: parse out inode number from "NLST -lai ." */
609 /* XXX FIXME: parse out sizein blocks from "NLST -lais ." */
611 if ((i = vfs_parse_filetype(*(p++))) == -1)
615 if (*p == ' ') /* Notwell 4 */
618 if (strlen (p) <= 8 || p [8] != ']')
620 /* Should parse here the Notwell permissions :) */
622 if (S_ISDIR (st->st_mode))
623 st->st_mode |= (S_IRUSR | S_IRGRP | S_IROTH | S_IWUSR | S_IXUSR | S_IXGRP | S_IXOTH);
625 st->st_mode |= (S_IRUSR | S_IRGRP | S_IROTH | S_IWUSR);
629 if ((i = vfs_parse_filemode(p)) == -1)
634 /* This is for an extra ACL attribute (HP-UX) */
640 p_copy = g_strdup(p);
641 num_cols = vfs_split_text (p);
643 st->st_nlink = atol (columns [0]);
644 if (st->st_nlink < 0)
649 st->st_uid = finduid (columns [1]);
651 (void) unameToUid (columns [1], &st->st_uid);
654 st->st_uid = (uid_t) atol (columns [1]);
656 /* Mhm, the ls -lg did not produce a group field */
657 for (idx = 3; idx <= 5; idx++)
658 if (is_month(columns [idx], NULL) || is_week(columns [idx], NULL) || is_dos_date(columns[idx]))
661 if (idx == 6 || (idx == 5 && !S_ISCHR (st->st_mode) && !S_ISBLK (st->st_mode)))
664 /* We don't have gid */
665 if (idx == 3 || (idx == 4 && (S_ISCHR(st->st_mode) || S_ISBLK (st->st_mode))))
668 /* We have gid field */
670 st->st_gid = (gid_t) atol (columns [2]);
673 st->st_gid = findgid (columns [2]);
675 (void) gnameToGid (columns [1], &st->st_gid);
681 if (S_ISCHR (st->st_mode) || S_ISBLK (st->st_mode)){
684 if (!is_num (idx2) || sscanf(columns [idx2], " %d,", &maj) != 1)
687 if (!is_num (++idx2) || sscanf(columns [idx2], " %d", &min) != 1)
691 st->st_rdev = ((maj & 0xff) << 8) | (min & 0xffff00ff);
696 /* Common file size */
700 st->st_size = (size_t) atol (columns [idx2]);
706 idx = vfs_parse_filedate(idx, &st->st_mtime);
709 /* Use resulting time value */
710 st->st_atime = st->st_ctime = st->st_mtime;
713 #ifdef HAVE_ST_BLKSIZE
714 st->st_blksize = 512;
716 #ifdef HAVE_ST_BLOCKS
717 st->st_blocks = (st->st_size + 511) / 512;
720 for (i = idx + 1, idx2 = 0; i < num_cols; i++ )
721 if (strcmp (columns [i], "->") == 0){
726 if (((S_ISLNK (st->st_mode) ||
727 (num_cols == idx + 3 && st->st_nlink > 1))) /* Maybe a hardlink? (in extfs) */
734 t = g_strndup (p_copy + column_ptr [idx], column_ptr [idx2] - column_ptr [idx] - 1);
736 int nb = column_ptr [idx2] - column_ptr [idx] - 1;
738 strncpy(t, p_copy + column_ptr [idx], nb);
743 t = g_strdup (p_copy + column_ptr [idx2+1]);
745 if (t [tlen-1] == '\r' || t [tlen-1] == '\n')
747 if (t [tlen-2] == '\r' || t [tlen-2] == '\n')
753 /* Extract the filename from the string copy, not from the columns
754 * this way we have a chance of entering hidden directories like ". ."
758 *filename = g_strdup (columns [idx++]);
763 t = g_strdup (p_copy + column_ptr [idx]); idx++;
766 if (t [tlen-1] == '\r' || t [tlen-1] == '\n')
768 if (t [tlen-2] == '\r' || t [tlen-2] == '\n')
782 static int errorcount = 0;
784 if (++errorcount < 5) {
785 message_1s (1, "Could not parse:", p_copy);
786 } else if (errorcount == 5)
787 message_1s (1, "More parsing errors will be ignored.", "(sorry)" );
792 if (p_copy != p) /* Carefull! */
809 static size_t ftpBufAlloced = 0;
814 static /*@only@*/ char * ftpBuf = NULL;
816 #define alloca_strdup(_s) strcpy(alloca(strlen(_s)+1), (_s))
819 static int ftpNLST(const char * url, ftpSysCall_t ftpSysCall,
820 /*@out@*/ /*@null@*/ struct stat * st,
821 /*@out@*/ /*@null@*/ char * rlbuf, size_t rlbufsiz)
822 /*@globals fileSystem @*/
823 /*@modifies *st, *rlbuf, fileSystem @*/
827 int bufLength, moretodo;
828 const char *n, *ne, *o, *oe;
837 n = ne = o = oe = NULL;
838 (void) urlPath(url, &path);
842 switch (ftpSysCall) {
844 fd = ftpOpen(url, 0, 0, &u);
845 if (fd == NULL || u == NULL)
848 u->openError = ftpReq(fd, "LIST", path);
851 urldn = alloca_strdup(url);
853 if ((bn = strrchr(urldn, '/')) == NULL)
862 rc = ftpChdir(urldn); /* XXX don't care about CWD */
866 fd = ftpOpen(url, 0, 0, &u);
867 if (fd == NULL || u == NULL)
870 /* XXX possibly should do "NLST -lais" to get st_ino/st_blocks also */
871 u->openError = ftpReq(fd, "NLST", "-la");
873 if (bn == NULL || nbn <= 0) {
880 if (u->openError < 0) {
881 fd = fdLink(fd, "error data (ftpStat)");
886 if (ftpBufAlloced == 0 || ftpBuf == NULL) {
887 ftpBufAlloced = _url_iobuf_size;
888 ftpBuf = xcalloc(ftpBufAlloced, sizeof(ftpBuf[0]));
897 /* XXX FIXME: realloc ftpBuf if < ~128 chars remain */
898 if ((ftpBufAlloced - bufLength) < (1024+80)) {
900 ftpBuf = xrealloc(ftpBuf, ftpBufAlloced);
902 s = se = ftpBuf + bufLength;
905 rc = fdFgets(fd, se, (ftpBufAlloced - bufLength));
910 if (ftpSysCall == DO_FTP_GLOB) { /* XXX HACK */
911 bufLength += strlen(se);
915 for (s = se; *s != '\0'; s = se) {
918 while (*se && *se != '\n') se++;
919 if (se > s && se[-1] == '\r') se[-1] = '\0';
921 /*@innerbreak@*/ break;
924 if (!strncmp(s, "total ", sizeof("total ")-1))
925 /*@innercontinue@*/ continue;
928 for (bingo = 0, n = se; n >= s; n--) {
932 /*@switchbreak@*/ break;
934 if (o || !(n[-3] == ' ' && n[-2] == '-' && n[-1] == '>')) {
935 while (*(++n) == ' ')
938 /*@switchbreak@*/ break;
940 for (o = n + 1; *o == ' '; o++)
944 /*@switchbreak@*/ break;
946 /*@switchbreak@*/ break;
949 /*@innerbreak@*/ break;
952 if (nbn != (ne - n)) /* Same name length? */
953 /*@innercontinue@*/ continue;
954 if (strncmp(n, bn, nbn)) /* Same name? */
955 /*@innercontinue@*/ continue;
958 /*@innerbreak@*/ break;
961 if (moretodo && se > s) {
962 bufLength = se - s - 1;
964 memmove(ftpBuf, s, bufLength);
970 switch (ftpSysCall) {
973 /* XXX FIXME: symlink, replace urldn/bn from [o,oe) and restart */
977 if (st == NULL || !(n && ne)) {
980 rc = ((vfs_parse_ls_lga(s, st, NULL, NULL) > 0) ? 0 : -1);
983 case DO_FTP_READLINK:
984 if (rlbuf == NULL || !(o && oe)) {
990 memcpy(rlbuf, o, rc);
996 rc = 0; /* XXX WRONG WRONG WRONG */
999 rc = 0; /* XXX WRONG WRONG WRONG */
1004 (void) ufdClose(fd);
1009 static const char * statstr(struct stat * st)
1011 static char buf[1024];
1012 sprintf(buf, "*** dev %x ino %x mode %0o nlink %d uid %d gid %d rdev %x size %x\n",
1013 (unsigned)st->st_dev,
1014 (unsigned)st->st_ino,
1019 (unsigned)st->st_rdev,
1020 (unsigned)st->st_size);
1024 static int ftp_st_ino = 0x1000;
1026 static int ftpStat(const char * path, /*@out@*/ struct stat *st)
1027 /*@globals fileSystem @*/
1028 /*@modifies *st, fileSystem @*/
1031 rc = ftpNLST(path, DO_FTP_STAT, st, NULL, 0);
1033 fprintf(stderr, "*** ftpStat(%s) rc %d\n%s", path, rc, statstr(st));
1034 /* XXX fts(3) needs/uses st_ino, make something up for now. */
1035 if (st->st_ino == 0)
1036 st->st_ino = ftp_st_ino++;
1040 static int ftpLstat(const char * path, /*@out@*/ struct stat *st)
1041 /*@globals fileSystem @*/
1042 /*@modifies *st, fileSystem @*/
1045 rc = ftpNLST(path, DO_FTP_LSTAT, st, NULL, 0);
1047 fprintf(stderr, "*** ftpLstat(%s) rc %d\n%s\n", path, rc, statstr(st));
1048 st->st_ino = ftp_st_ino++;
1049 /* XXX fts(3) needs/uses st_ino, make something up for now. */
1050 if (st->st_ino == 0)
1051 st->st_ino = ftp_st_ino++;
1055 static int ftpReadlink(const char * path, /*@out@*/ char * buf, size_t bufsiz)
1056 /*@globals fileSystem @*/
1057 /*@modifies *buf, fileSystem @*/
1060 rc = ftpNLST(path, DO_FTP_READLINK, NULL, buf, bufsiz);
1062 fprintf(stderr, "*** ftpReadlink(%s) rc %d\n", path, rc);
1066 struct __dirstream {
1067 int fd; /* File descriptor. */
1068 char * data; /* Directory block. */
1069 size_t allocation; /* Space allocated for the block. */
1070 size_t size; /* Total valid data in the block. */
1071 size_t offset; /* Current offset into the block. */
1072 off_t filepos; /* Position of next entry to read. */
1073 pthread_mutex_t lock; /* Mutex lock for this structure. */
1076 static int ftpmagicdir = 0x8440291;
1077 #define ISFTPMAGIC(_dir) (!memcmp((_dir), &ftpmagicdir, sizeof(ftpmagicdir)))
1079 static DIR * ftpOpendir(const char * path)
1084 const char * s, * sb, * se;
1093 fprintf(stderr, "*** ftpOpendir(%s)\n", path);
1094 rc = ftpNLST(path, DO_FTP_GLOB, NULL, NULL, 0);
1099 * ftpBuf now contains absolute paths, newline terminated.
1100 * Calculate the number of bytes to hold the directory info.
1102 nb = sizeof(".") + sizeof("..");
1106 while ((c = *se) != '\0') {
1114 for (sb = se; sb > s && sb[-1] != ' '; sb--)
1120 if (*se == '\n') se++;
1129 nb += sizeof(*dir) + sizeof(*dp) + ((ac + 1) * sizeof(*av)) + (ac + 1);
1130 dir = xcalloc(1, nb);
1131 dp = (struct dirent *) (dir + 1);
1132 av = (const char **) (dp + 1);
1133 dt = (char *) (av + (ac + 1));
1134 t = (char *) (dt + ac + 1);
1136 dir->fd = ftpmagicdir;
1137 dir->data = (char *) dp;
1138 dir->allocation = nb;
1144 dt[ac] = DT_DIR; av[ac++] = t; t = stpcpy(t, "."); t++;
1145 dt[ac] = DT_DIR; av[ac++] = t; t = stpcpy(t, ".."); t++;
1148 while ((c = *se) != '\0') {
1158 case 'p': dt[ac] = DT_FIFO; break;
1159 case 'c': dt[ac] = DT_CHR; break;
1160 case 'd': dt[ac] = DT_DIR; break;
1161 case 'b': dt[ac] = DT_BLK; break;
1162 case '-': dt[ac] = DT_REG; break;
1163 case 'l': dt[ac] = DT_LNK; break;
1164 case 's': dt[ac] = DT_SOCK; break;
1165 default: dt[ac] = DT_UNKNOWN; break;
1167 for (sb = se; sb > s && sb[-1] != ' '; sb--)
1171 t = stpncpy(t, sb, (se - sb));
1173 if (*se == '\n') se++;
1186 static struct dirent * ftpReaddir(DIR * dir)
1194 if (dir == NULL || !ISFTPMAGIC(dir) || dir->data == NULL) {
1195 /* XXX TODO: EBADF errno. */
1199 dp = (struct dirent *) dir->data;
1200 av = (const char **) (dp + 1);
1202 dt = (char *) (av + (ac + 1));
1203 i = dir->offset + 1;
1205 if (i < 0 || i >= ac || av[i] == NULL)
1210 /* XXX glob(3) uses REAL_DIR_ENTRY(dp) test on d_ino */
1211 dp->d_ino = i + 1; /* W2DO? */
1212 dp->d_off = 0; /* W2DO? */
1213 dp->d_reclen = 0; /* W2DO? */
1216 strncpy(dp->d_name, av[i], sizeof(dp->d_name));
1218 fprintf(stderr, "*** ftpReaddir(%p) %p \"%s\"\n", dir, dp, dp->d_name);
1223 static int ftpClosedir(DIR * dir)
1226 fprintf(stderr, "*** ftpClosedir(%p)\n", dir);
1227 if (dir == NULL || !ISFTPMAGIC(dir)) {
1228 /* XXX TODO: EBADF errno. */
1236 int Stat(const char * path, struct stat * st)
1239 int ut = urlPath(path, &lpath);
1242 fprintf(stderr, "*** Stat(%s,%p)\n", path, st);
1245 return ftpStat(path, st);
1246 /*@notreached@*/ break;
1247 case URL_IS_HTTP: /* XXX WRONG WRONG WRONG */
1251 case URL_IS_UNKNOWN:
1256 /*@notreached@*/ break;
1258 return stat(path, st);
1261 int Lstat(const char * path, struct stat * st)
1264 int ut = urlPath(path, &lpath);
1267 fprintf(stderr, "*** Lstat(%s,%p)\n", path, st);
1270 return ftpLstat(path, st);
1271 /*@notreached@*/ break;
1272 case URL_IS_HTTP: /* XXX WRONG WRONG WRONG */
1276 case URL_IS_UNKNOWN:
1281 /*@notreached@*/ break;
1283 return lstat(path, st);
1286 int Readlink(const char * path, char * buf, size_t bufsiz)
1289 int ut = urlPath(path, &lpath);
1293 return ftpReadlink(path, buf, bufsiz);
1294 /*@notreached@*/ break;
1295 case URL_IS_HTTP: /* XXX WRONG WRONG WRONG */
1299 case URL_IS_UNKNOWN:
1304 /*@notreached@*/ break;
1306 return readlink(path, buf, bufsiz);
1309 int Access(const char * path, int amode)
1312 int ut = urlPath(path, &lpath);
1315 fprintf(stderr, "*** Access(%s,%d)\n", path, amode);
1317 case URL_IS_FTP: /* XXX WRONG WRONG WRONG */
1318 case URL_IS_HTTP: /* XXX WRONG WRONG WRONG */
1322 case URL_IS_UNKNOWN:
1327 /*@notreached@*/ break;
1329 return access(path, amode);
1332 int Glob(const char *pattern, int flags,
1333 int errfunc(const char * epath, int eerrno), glob_t *pglob)
1336 int ut = urlPath(pattern, &lpath);
1340 fprintf(stderr, "*** Glob(%s,0x%x,%p,%p)\n", pattern, (unsigned)flags, (void *)errfunc, pglob);
1344 pglob->gl_closedir = Closedir;
1345 pglob->gl_readdir = Readdir;
1346 pglob->gl_opendir = Opendir;
1347 pglob->gl_lstat = Lstat;
1348 pglob->gl_stat = Stat;
1349 flags |= GLOB_ALTDIRFUNC;
1351 case URL_IS_HTTP: /* XXX WRONG WRONG WRONG */
1355 case URL_IS_UNKNOWN:
1360 /*@notreached@*/ break;
1362 return glob(pattern, flags, errfunc, pglob);
1365 void Globfree(glob_t *pglob)
1368 fprintf(stderr, "*** Globfree(%p)\n", pglob);
1372 DIR * Opendir(const char * path)
1375 int ut = urlPath(path, &lpath);
1378 fprintf(stderr, "*** Opendir(%s)\n", path);
1381 return ftpOpendir(path);
1382 /*@notreached@*/ break;
1383 case URL_IS_HTTP: /* XXX WRONG WRONG WRONG */
1387 case URL_IS_UNKNOWN:
1392 /*@notreached@*/ break;
1394 /*@-dependenttrans@*/
1395 return opendir(path);
1396 /*@=dependenttrans@*/
1400 struct dirent * Readdir(DIR * dir)
1403 fprintf(stderr, "*** Readdir(%p)\n", (void *)dir);
1404 if (dir == NULL || ISFTPMAGIC(dir))
1405 return ftpReaddir(dir);
1406 return readdir(dir);
1409 int Closedir(DIR * dir)
1412 fprintf(stderr, "*** Closedir(%p)\n", (void *)dir);
1413 if (dir == NULL || ISFTPMAGIC(dir))
1414 return ftpClosedir(dir);
1415 return closedir(dir);