]> granicus.if.org Git - php/commitdiff
Don't rely on ANSI tmpfile(), use the streams layer instead, it'll deal with platform...
authorSara Golemon <pollita@php.net>
Thu, 4 Mar 2004 22:24:27 +0000 (22:24 +0000)
committerSara Golemon <pollita@php.net>
Thu, 4 Mar 2004 22:24:27 +0000 (22:24 +0000)
ext/ftp/ftp.c

index 37b6520c1bee0979fd577888394669d8c9a87030..fd3cd461ec886c941c36654465fcc5622c36c424 100644 (file)
@@ -1607,7 +1607,7 @@ data_close(ftpbuf_t *ftp, databuf_t *data)
 char**
 ftp_genlist(ftpbuf_t *ftp, const char *cmd, const char *path TSRMLS_DC)
 {
-       FILE            *tmpfp = NULL;
+       php_stream      *tmpstream = NULL;
        databuf_t       *data = NULL;
        char            *ptr;
        int             ch, lastch;
@@ -1618,7 +1618,7 @@ ftp_genlist(ftpbuf_t *ftp, const char *cmd, const char *path TSRMLS_DC)
        char            *text;
 
 
-       if ((tmpfp = tmpfile()) == NULL) {
+       if ((tmpstream = php_stream_fopen_tmpfile()) == NULL) {
                php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to create temporary file.  Check permissions in temporary files directory.");
                return NULL;
        }
@@ -1651,7 +1651,7 @@ ftp_genlist(ftpbuf_t *ftp, const char *cmd, const char *path TSRMLS_DC)
                        goto bail;
                }
 
-               fwrite(data->buf, rcvd, 1, tmpfp);
+               php_stream_write(tmpstream, data->buf, rcvd);
 
                size += rcvd;
                for (ptr = data->buf; rcvd; rcvd--, ptr++) {
@@ -1666,11 +1666,7 @@ ftp_genlist(ftpbuf_t *ftp, const char *cmd, const char *path TSRMLS_DC)
 
        ftp->data = data = data_close(ftp, data);
 
-       if (ferror(tmpfp)) {
-               goto bail;
-       }
-
-       rewind(tmpfp);
+       php_stream_rewind(tmpstream);
 
        ret = safe_emalloc((lines + 1), sizeof(char**), size * sizeof(char*));
 
@@ -1678,7 +1674,7 @@ ftp_genlist(ftpbuf_t *ftp, const char *cmd, const char *path TSRMLS_DC)
        text = (char*) (ret + lines + 1);
        *entry = text;
        lastch = 0;
-       while ((ch = getc(tmpfp)) != EOF) {
+       while ((ch = php_stream_getc(tmpstream)) != EOF) {
                if (ch == '\n' && lastch == '\r') {
                        *(text - 1) = 0;
                        *++entry = text;
@@ -1689,10 +1685,7 @@ ftp_genlist(ftpbuf_t *ftp, const char *cmd, const char *path TSRMLS_DC)
        }
        *entry = NULL;
 
-       if (ferror(tmpfp)) {
-               goto bail;
-       }
-       fclose(tmpfp);
+       php_stream_close(tmpstream);
 
        if (!ftp_getresp(ftp) || (ftp->resp != 226 && ftp->resp != 250)) {
                efree(ret);
@@ -1702,7 +1695,7 @@ ftp_genlist(ftpbuf_t *ftp, const char *cmd, const char *path TSRMLS_DC)
        return ret;
 bail:
        ftp->data = data_close(ftp, data);
-       fclose(tmpfp);
+       php_stream_close(tmpstream);
        if (ret)
                efree(ret);
        return NULL;