cvs: php4 /ext/ftp/ ftp.c php_ftp.c

[email protected] ("Andrew Skalski")
Newsgroups php.version4
Message-ID <cvsaskalski959030218@cvsserver>
askalski		Mon May 22 23:16:58 2000 EDT

  Modified files:
    /php4/ext/ftp	ftp.c php_ftp.c 
  Log:
  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)
  
  
Index: php4/ext/ftp/ftp.c
diff -u php4/ext/ftp/ftp.c:1.16 php4/ext/ftp/ftp.c:1.17
--- php4/ext/ftp/ftp.c:1.16	Thu May  4 12:38:13 2000
+++ php4/ext/ftp/ftp.c	Mon May 22 23:16:58 2000
@@ -28,7 +28,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: ftp.c,v 1.16 2000/05/04 10:38:13 sas Exp $ */
+/* $Id: ftp.c,v 1.17 2000/05/22 21:16:58 askalski Exp $ */
 
 #include "php.h"
 
@@ -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 @@
 
 bail:
 	if (fd != -1)
-		close(fd);
+		closesocket(fd);
 	free(ftp);
 	return NULL;
 }
@@ -168,7 +174,7 @@
 	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 @@
 			sizeof(ftp->pasvaddr)) == -1)
 		{
 			perror("connect");
-			close(fd);
+			closesocket(fd);
 			free(data);
 			return NULL;
 		}
@@ -1034,7 +1040,7 @@
 
 bail:
 	if (fd != -1)
-		close(fd);
+		closesocket(fd);
 	free(data);
 	return NULL;
 }
@@ -1051,7 +1057,7 @@
 
 	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 @@
 	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;
 }
Index: php4/ext/ftp/php_ftp.c
diff -u php4/ext/ftp/php_ftp.c:1.19 php4/ext/ftp/php_ftp.c:1.20
--- php4/ext/ftp/php_ftp.c:1.19	Sun May  7 05:20:37 2000
+++ php4/ext/ftp/php_ftp.c	Mon May 22 23:16:58 2000
@@ -28,7 +28,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: php_ftp.c,v 1.19 2000/05/07 03:20:37 sas Exp $ */
+/* $Id: php_ftp.c,v 1.20 2000/05/22 21:16:58 askalski Exp $ */
 
 #include "php.h"
 
@@ -551,7 +551,11 @@
 		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 @@
 	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;
 	}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.