summaryrefslogtreecommitdiff
path: root/ext/ftp
diff options
context:
space:
mode:
authorSara Golemon <pollita@php.net>2004-03-04 22:24:27 +0000
committerSara Golemon <pollita@php.net>2004-03-04 22:24:27 +0000
commit85aa47efaba1baf3b939f542e0560bd393e3e0bf (patch)
treec63f00cf24fd18d1e52d709e070f8c36b1aab509 /ext/ftp
parentab204a36e0b0d877b1e7d821d50386a1bfab90d4 (diff)
downloadphp-git-85aa47efaba1baf3b939f542e0560bd393e3e0bf.tar.gz
Don't rely on ANSI tmpfile(), use the streams layer instead, it'll deal with platform issues.
Diffstat (limited to 'ext/ftp')
-rw-r--r--ext/ftp/ftp.c21
1 files changed, 7 insertions, 14 deletions
diff --git a/ext/ftp/ftp.c b/ext/ftp/ftp.c
index 37b6520c1b..fd3cd461ec 100644
--- a/ext/ftp/ftp.c
+++ b/ext/ftp/ftp.c
@@ -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;