1995-04-25 15:05:11 +00:00
|
|
|
/*
|
|
|
|
Library for ftpd clients.(libftp)
|
|
|
|
Copyright by Oleg Orel
|
|
|
|
All rights reserved.
|
1995-05-30 05:51:47 +00:00
|
|
|
|
|
|
|
This library is desined for free, non-commercial software creation.
|
|
|
|
It is changeable and can be improved. The author would greatly appreciate
|
1995-04-25 15:05:11 +00:00
|
|
|
any advises, new components and patches of the existing programs.
|
|
|
|
Commercial usage is also possible with participation of it's author.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <FtpLibrary.h>
|
|
|
|
|
|
|
|
#define NFSD 256
|
|
|
|
|
|
|
|
static int fds_types[NFDS];
|
|
|
|
static int init=0;
|
|
|
|
|
|
|
|
enum {T_EMPTY=0,T_FILE,T_STREAM,T_PIPE,T_FULL};
|
|
|
|
|
|
|
|
FILE *Ftpfopen(char *filename,char *mode)
|
|
|
|
{
|
|
|
|
FILE *fp;
|
1995-05-30 05:51:47 +00:00
|
|
|
|
1995-04-25 15:05:11 +00:00
|
|
|
if (!init)
|
1995-05-30 05:51:47 +00:00
|
|
|
{
|
1995-04-25 15:05:11 +00:00
|
|
|
bzero(fds_types,NFDS*sizeof(fds_types[0]));
|
|
|
|
init=1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!strcmp(filename,"*STDIN*") || (!strcmp(filename,"-") && (mode[0]=='r')) )
|
|
|
|
{
|
|
|
|
fds_types[fileno(stdin)]=T_STREAM;
|
|
|
|
return stdin;
|
|
|
|
}
|
1995-05-30 05:51:47 +00:00
|
|
|
|
1995-04-25 15:05:11 +00:00
|
|
|
if (!strcmp(filename,"*STDOUT*") || (!strcmp(filename,"-") && (mode[0]=='w')))
|
|
|
|
{
|
|
|
|
fds_types[fileno(stdout)]=T_STREAM;
|
|
|
|
return stdout;
|
|
|
|
}
|
1995-05-30 05:51:47 +00:00
|
|
|
|
1995-04-25 15:05:11 +00:00
|
|
|
if (strcmp(filename,"*STDERR*")==0)
|
|
|
|
{
|
|
|
|
fds_types[fileno(stderr)]=T_STREAM;
|
|
|
|
return stderr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1995-05-30 05:51:47 +00:00
|
|
|
|
|
|
|
if (*filename=='|')
|
1995-04-25 15:05:11 +00:00
|
|
|
{
|
|
|
|
fp=popen(filename+1,mode);
|
|
|
|
if (fp==NULL) return fp;
|
|
|
|
fds_types[fileno(fp)]=T_PIPE;
|
|
|
|
return fp;
|
|
|
|
}
|
|
|
|
|
|
|
|
fp=FtpFullOpen(filename,mode);
|
|
|
|
if (fp==NULL) return fp;
|
|
|
|
fds_types[fileno(fp)]=T_FILE;
|
|
|
|
return fp;
|
1995-05-30 05:51:47 +00:00
|
|
|
|
1995-04-25 15:05:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int Ftpfclose(FILE *fp)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (!init)
|
1995-05-30 05:51:47 +00:00
|
|
|
{
|
1995-04-25 15:05:11 +00:00
|
|
|
bzero(fds_types,NFDS*sizeof(fds_types[0]));
|
|
|
|
init=1;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (fds_types[fileno(fp)])
|
|
|
|
{
|
1995-05-30 05:51:47 +00:00
|
|
|
|
1995-04-25 15:05:11 +00:00
|
|
|
case T_FILE:
|
1995-05-30 05:51:47 +00:00
|
|
|
|
1995-04-25 15:05:11 +00:00
|
|
|
return FtpFullClose(fp);
|
1995-05-30 05:51:47 +00:00
|
|
|
|
1995-04-25 15:05:11 +00:00
|
|
|
case T_STREAM:
|
|
|
|
|
|
|
|
return fflush(fp);
|
1995-05-30 05:51:47 +00:00
|
|
|
|
1995-04-25 15:05:11 +00:00
|
|
|
case T_PIPE:
|
1995-05-30 05:51:47 +00:00
|
|
|
|
1995-04-25 15:05:11 +00:00
|
|
|
return pclose(fp);
|
1995-05-30 05:51:47 +00:00
|
|
|
|
1995-04-25 15:05:11 +00:00
|
|
|
default:
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|