made changes to work with Win32;

replaced fstat() with stat() call and bail out if local file not found.
This commit is contained in:
Gunter Knauf 2008-02-19 16:13:52 +00:00
parent d2125cf501
commit 7a5596bf02

View File

@ -14,7 +14,11 @@
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <fcntl.h> #include <fcntl.h>
#ifdef WIN32
#include <io.h>
#else
#include <unistd.h> #include <unistd.h>
#endif
/* /*
* This example shows an FTP upload, with a rename of the file just after * This example shows an FTP upload, with a rename of the file just after
@ -32,8 +36,7 @@ int main(int argc, char **argv)
{ {
CURL *curl; CURL *curl;
CURLcode res; CURLcode res;
FILE * hd_src ; FILE *hd_src;
int hd ;
struct stat file_info; struct stat file_info;
struct curl_slist *headerlist=NULL; struct curl_slist *headerlist=NULL;
@ -41,13 +44,13 @@ int main(int argc, char **argv)
static const char buf_2 [] = "RNTO " RENAME_FILE_TO; static const char buf_2 [] = "RNTO " RENAME_FILE_TO;
/* get the file size of the local file */ /* get the file size of the local file */
hd = open(LOCAL_FILE, O_RDONLY) ; if (stat(LOCAL_FILE, &file_info)) {
fstat(hd, &file_info); printf("Couldnt open '%s': %s\n", LOCAL_FILE, strerror(errno));
close(hd) ; exit(1);
}
printf("Local file size: %ld bytes.\n", file_info.st_size);
/* get a FILE * of the same file, could also be made with /* get a FILE * of the same file */
fdopen() from the previous descriptor, but hey this is just
an example! */
hd_src = fopen(LOCAL_FILE, "rb"); hd_src = fopen(LOCAL_FILE, "rb");
/* In windows, this will init the winsock stuff */ /* In windows, this will init the winsock stuff */