Removed non portable -v flag for rm command.
[uftps.git] / file_stats.c
blob11220d9ef3d5e4cddee8914818f488e800b8af9b
1 /*
2 * User FTP Server, Share folders over FTP without being root.
3 * Copyright (C) 2008 Isaac Jurado
5 * This program is free software; you can redistribute it and/or modify it under
6 * the terms of the GNU General Public License as published by the Free Software
7 * Foundation; either version 2 of the License, or (at your option) any later
8 * version.
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 * details.
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
20 #include "uftps.h"
21 #ifdef __MINGW32__
22 # include "hase.h"
23 #else
24 # include <sys/stat.h>
25 # include <time.h>
26 #endif
27 #include <stdio.h>
31 * File status query.
33 * Here we implement some commands (SIZE, MDTM) that share the need of calling
34 * stat() over a given file, no matter the fields looked up. It's handy to
35 * merge all of them here so safety checks are not replicated.
37 void file_stats (int type)
39 int l = 0, e;
40 struct stat s;
41 struct tm *t;
43 if (SS.arg == NULL)
45 warning("Stat type %d without argument", type);
46 reply_c("501 Argument required.\r\n");
47 return;
49 expand_arg();
51 e = lstat(SS.arg, &s);
52 if (e == -1 || (!S_ISREG(s.st_mode) && !S_ISDIR(s.st_mode)))
54 if (e == -1)
55 error("Stating file %s", SS.arg);
56 else
57 warning("Path %s is not file nor directory", SS.arg);
58 reply_c("550 Could not stat file.\r\n");
59 return;
62 switch (type)
64 case 0: /* MDTM */
65 t = gmtime(&s.st_mtime);
66 if (t == NULL)
68 error("Converting time of %s", SS.arg);
69 reply_c("550 Error converting time.\r\n");
70 return;
73 l = snprintf(SS.aux, LINE_SIZE, "213 %4d%02d%02d%02d%02d%02d\r\n",
74 t->tm_year + 1900, t->tm_mon, t->tm_mday,
75 t->tm_hour, t->tm_min, t->tm_sec);
76 break;
78 case 1: /* SIZE */
79 #ifdef __MINGW32__
80 l = snprintf(SS.aux, LINE_SIZE, "213 %I64d\r\n", s.st_size);
81 #else
82 l = snprintf(SS.aux, LINE_SIZE, "213 %lld\r\n",
83 (long long) s.st_size);
84 #endif
87 reply(SS.aux, l);