summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Skalski <askalski@php.net>2000-05-22 21:16:58 +0000
committerAndrew Skalski <askalski@php.net>2000-05-22 21:16:58 +0000
commit3ac4c96641ab50319d87eb0dc220b215e9d06b5f (patch)
tree8e6dec4f009af7df37f5950f0e598756d9fb4239
parent072755ca8d26bd5b182f4a025fecc290fed349d2 (diff)
downloadphp-git-3ac4c96641ab50319d87eb0dc220b215e9d06b5f.tar.gz
applied Luca Montecchiani's win32 fixes (open files in binary mode
using the "b" fopen flag, and use closesocket rather than close when closing sockets)
-rw-r--r--ext/ftp/ftp.c20
-rw-r--r--ext/ftp/php_ftp.c8
2 files changed, 21 insertions, 7 deletions
diff --git a/ext/ftp/ftp.c b/ext/ftp/ftp.c
index 98605d1e0e..fa167a62d8 100644
--- a/ext/ftp/ftp.c
+++ b/ext/ftp/ftp.c
@@ -52,6 +52,12 @@
#include "ftp.h"
+/* define closesocket macro for portability */
+#if !defined(WIN32) && !defined(WINNT)
+#undef closesocket
+#define closesocket close
+#endif
+
/* sends an ftp command, returns true on success, false on error.
* it sends the string "cmd args\r\n" if args is non-null, or
* "cmd\r\n" if args is null
@@ -156,7 +162,7 @@ ftp_open(const char *host, short port)
bail:
if (fd != -1)
- close(fd);
+ closesocket(fd);
free(ftp);
return NULL;
}
@@ -168,7 +174,7 @@ ftp_close(ftpbuf_t *ftp)
if (ftp == NULL)
return NULL;
if (ftp->fd != -1)
- close(ftp->fd);
+ closesocket(ftp->fd);
ftp_gc(ftp);
free(ftp);
return NULL;
@@ -981,7 +987,7 @@ ftp_getdata(ftpbuf_t *ftp)
sizeof(ftp->pasvaddr)) == -1)
{
perror("connect");
- close(fd);
+ closesocket(fd);
free(data);
return NULL;
}
@@ -1034,7 +1040,7 @@ ftp_getdata(ftpbuf_t *ftp)
bail:
if (fd != -1)
- close(fd);
+ closesocket(fd);
free(data);
return NULL;
}
@@ -1051,7 +1057,7 @@ data_accept(databuf_t *data)
size = sizeof(addr);
data->fd = my_accept(data->listener, (struct sockaddr*) &addr, &size);
- close(data->listener);
+ closesocket(data->listener);
data->listener = -1;
if (data->fd == -1) {
@@ -1069,9 +1075,9 @@ data_close(databuf_t *data)
if (data == NULL)
return NULL;
if (data->listener != -1)
- close(data->listener);
+ closesocket(data->listener);
if (data->fd != -1)
- close(data->fd);
+ closesocket(data->fd);
free(data);
return NULL;
}
diff --git a/ext/ftp/php_ftp.c b/ext/ftp/php_ftp.c
index 4f967d1ee0..e76f3c7096 100644
--- a/ext/ftp/php_ftp.c
+++ b/ext/ftp/php_ftp.c
@@ -551,7 +551,11 @@ PHP_FUNCTION(ftp_get)
RETURN_FALSE;
}
+#if defined(WIN32) || defined(WINNT)
+ if ((outfp = V_FOPEN(arg2->value.str.val, "wb")) == NULL) {
+#else
if ((outfp = V_FOPEN(arg2->value.str.val, "w")) == NULL) {
+#endif
fclose(tmpfp);
php_error(E_WARNING, "error opening %s", arg2->value.str.val);
RETURN_FALSE;
@@ -635,7 +639,11 @@ PHP_FUNCTION(ftp_put)
convert_to_string(arg3);
XTYPE(xtype, arg4);
+#if defined(WIN32) || defined(WINNT)
+ if ((infp = V_FOPEN(arg3->value.str.val, "rb")) == NULL) {
+#else
if ((infp = V_FOPEN(arg3->value.str.val, "r")) == NULL) {
+#endif
php_error(E_WARNING, "error opening %s", arg3->value.str.val);
RETURN_FALSE;
}