Unbreak build: libftpio gropes inside struct __sFILE. Implement

accessor functions for its benefit now thaat FILE is opaque.
I'm sure there's a better way. I leave that for people to work
on in a src tree that isn't broken.

Pointy hat: jhb
This commit is contained in:
Marcel Moolenaar 2008-05-03 20:09:44 +00:00
parent 957d0a092d
commit 430f2c8721
3 changed files with 28 additions and 19 deletions

View File

@ -249,6 +249,9 @@ int setlinebuf(FILE *);
int vasprintf(char **, const char *, __va_list) int vasprintf(char **, const char *, __va_list)
__printflike(2, 0); __printflike(2, 0);
void *__fgetcookie(FILE *);
void __fsetfileno(FILE *, int);
/* /*
* The system error table contains messages for the first sys_nerr * The system error table contains messages for the first sys_nerr
* positive errno values. Use strerror() or strerror_r() from <string.h> * positive errno values. Use strerror() or strerror_r() from <string.h>

View File

@ -46,6 +46,20 @@ __FBSDID("$FreeBSD$");
#include "un-namespace.h" #include "un-namespace.h"
#include "local.h" #include "local.h"
void *
__fgetcookie(FILE *fp)
{
return (fp->_cookie);
}
void
__fsetfileno(FILE *fp, int fd)
{
fp->_file = fd;
}
/* /*
* Small standard I/O/seek/close functions. * Small standard I/O/seek/close functions.
*/ */

View File

@ -87,14 +87,6 @@ int FtpTimedOut;
/* FTP unhappy status codes */ /* FTP unhappy status codes */
#define FTP_TIMED_OUT 421 #define FTP_TIMED_OUT 421
/*
* XXX
* gross! evil! bad! We really need an access primitive for cookie in stdio itself.
* it's too convenient a hook to bury and it's already exported through funopen as it is, so...
* XXX
*/
#define fcookie(fp) ((fp)->_cookie)
/* Placeholder in case we want to do any pre-init stuff at some point */ /* Placeholder in case we want to do any pre-init stuff at some point */
int int
networkInit() networkInit()
@ -126,7 +118,7 @@ check_code(FTP_t ftp, int var, int preferred)
int int
ftpAscii(FILE *fp) ftpAscii(FILE *fp)
{ {
FTP_t ftp = fcookie(fp); FTP_t ftp = __fgetcookie(fp);
int i; int i;
if (!ftp->is_binary) if (!ftp->is_binary)
@ -141,7 +133,7 @@ ftpAscii(FILE *fp)
int int
ftpBinary(FILE *fp) ftpBinary(FILE *fp)
{ {
FTP_t ftp = fcookie(fp); FTP_t ftp = __fgetcookie(fp);
int i; int i;
if (ftp->is_binary) if (ftp->is_binary)
@ -155,7 +147,7 @@ ftpBinary(FILE *fp)
void void
ftpVerbose(FILE *fp, int status) ftpVerbose(FILE *fp, int status)
{ {
FTP_t ftp = fcookie(fp); FTP_t ftp = __fgetcookie(fp);
ftp->is_verbose = status; ftp->is_verbose = status;
} }
@ -163,7 +155,7 @@ int
ftpChdir(FILE *fp, char *dir) ftpChdir(FILE *fp, char *dir)
{ {
int i; int i;
FTP_t ftp = fcookie(fp); FTP_t ftp = __fgetcookie(fp);
i = cmd(ftp, "CWD %s", dir); i = cmd(ftp, "CWD %s", dir);
if (i < 0 || check_code(ftp, i, FTP_CHDIR_HAPPY)) if (i < 0 || check_code(ftp, i, FTP_CHDIR_HAPPY))
@ -174,7 +166,7 @@ ftpChdir(FILE *fp, char *dir)
int int
ftpErrno(FILE *fp) ftpErrno(FILE *fp)
{ {
FTP_t ftp = fcookie(fp); FTP_t ftp = __fgetcookie(fp);
return ftp->error; return ftp->error;
} }
@ -199,7 +191,7 @@ ftpGetSize(FILE *fp, char *name)
{ {
int i; int i;
char p[BUFSIZ], *cp, *ep; char p[BUFSIZ], *cp, *ep;
FTP_t ftp = fcookie(fp); FTP_t ftp = __fgetcookie(fp);
off_t size; off_t size;
check_passive(fp); check_passive(fp);
@ -225,7 +217,7 @@ ftpGetModtime(FILE *fp, char *name)
char p[BUFSIZ], *cp; char p[BUFSIZ], *cp;
struct tm t; struct tm t;
time_t t0 = time (0); time_t t0 = time (0);
FTP_t ftp = fcookie(fp); FTP_t ftp = __fgetcookie(fp);
int i; int i;
check_passive(fp); check_passive(fp);
@ -255,7 +247,7 @@ FILE *
ftpGet(FILE *fp, char *file, off_t *seekto) ftpGet(FILE *fp, char *file, off_t *seekto)
{ {
FILE *fp2; FILE *fp2;
FTP_t ftp = fcookie(fp); FTP_t ftp = __fgetcookie(fp);
check_passive(fp); check_passive(fp);
if (ftpBinary(fp) != SUCCESS) if (ftpBinary(fp) != SUCCESS)
@ -292,7 +284,7 @@ ftpLoginAf(char *host, int af, char *user, char *passwd, int port, int verbose,
fp = NULL; fp = NULL;
if (n && ftp_login_session(n, host, af, user, passwd, port, verbose) == SUCCESS) { if (n && ftp_login_session(n, host, af, user, passwd, port, verbose) == SUCCESS) {
fp = funopen(n, ftp_read_method, ftp_write_method, NULL, ftp_close_method); /* BSD 4.4 function! */ fp = funopen(n, ftp_read_method, ftp_write_method, NULL, ftp_close_method); /* BSD 4.4 function! */
fp->_file = n->fd_ctrl; __fsetfileno(fp, n->fd_ctrl);
} }
if (retcode) { if (retcode) {
if (!n) if (!n)
@ -319,7 +311,7 @@ FILE *
ftpPut(FILE *fp, char *file) ftpPut(FILE *fp, char *file)
{ {
FILE *fp2; FILE *fp2;
FTP_t ftp = fcookie(fp); FTP_t ftp = __fgetcookie(fp);
check_passive(fp); check_passive(fp);
if (ftp_file_op(ftp, "STOR", file, &fp2, "w", NULL) == SUCCESS) if (ftp_file_op(ftp, "STOR", file, &fp2, "w", NULL) == SUCCESS)
@ -330,7 +322,7 @@ ftpPut(FILE *fp, char *file)
int int
ftpPassive(FILE *fp, int st) ftpPassive(FILE *fp, int st)
{ {
FTP_t ftp = fcookie(fp); FTP_t ftp = __fgetcookie(fp);
ftp->is_passive = !!st; /* normalize "st" to zero or one */ ftp->is_passive = !!st; /* normalize "st" to zero or one */
return SUCCESS; return SUCCESS;