Removed non portable -v flag for rm command.
[uftps.git] / open_file.c
blob6618edf1597afc74c26a78fa92381eb6a8f7f110
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 <unistd.h>
26 # include <fcntl.h>
27 #endif
31 * Open the file specified in the argument after performing various checks.
32 * Returns the opened file descriptor when successful, -1 on error. The total
33 * size of the file is stored in "file_size".
35 * This function is the common code between all send_file() implementations.
36 * Note that, on error, everybody is notified so the invocation to this function
37 * is as simple as possible.
39 int open_file (off_t *file_size)
41 int f, e;
42 struct stat s;
44 if (SS.arg == NULL)
46 reply_c("501 Argument required.\r\n");
47 return -1;
49 expand_arg();
51 /* Avoid following symlinks, as usual */
52 e = lstat(SS.arg, &s);
53 if (e == -1 || !S_ISREG(s.st_mode))
55 if (e == -1)
56 error("Stating file %s", SS.arg);
57 else
58 warning("%s is not a regular file", SS.arg);
59 reply_c("550 Not a file.\r\n");
60 return -1;
62 *file_size = s.st_size;
64 f = open(SS.arg, O_RDONLY);
65 if (f == -1)
67 error("Opening file %s", SS.arg);
68 reply_c("550 Could not open file.\r\n");
71 return f;