X-Git-Url: https://perl5.git.perl.org/perl5.git/blobdiff_plain/6b88bc9c1f6d4b32c70e7ef68f8c65266e431623..d7341064bc2472128b060451c0da8ce62db49d9d:/djgpp/djgpp.c diff --git a/djgpp/djgpp.c b/djgpp/djgpp.c index 4d0d9fd..0e465b0 100644 --- a/djgpp/djgpp.c +++ b/djgpp/djgpp.c @@ -1,19 +1,5 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "EXTERN.h" -#include "perl.h" -#include "XSUB.h" +#define PERLIO_NOT_STDIO 0 +#include "djgpp.h" /* hold file pointer, command, mode, and the status of the command */ struct pipe_list { @@ -27,7 +13,7 @@ struct pipe_list { static struct pipe_list *pl = NULL; FILE * -popen (const char *cm, const char *md) /* program name, pipe mode */ +djgpp_popen (const char *cm, const char *md) /* program name, pipe mode */ { struct pipe_list *l1; int fd; @@ -75,7 +61,7 @@ popen (const char *cm, const char *md) /* program name, pipe mode */ } int -pclose (FILE *pp) +djgpp_pclose (FILE *pp) { struct pipe_list *l1, **l2; /* list pointers */ int retval=-1; /* function return value */ @@ -117,23 +103,22 @@ pclose (FILE *pp) #define EXECF_EXEC 1 static int -convretcode (int rc,char *prog,int fl) +convretcode (pTHX_ int rc,char *prog,int fl) { - if (rc < 0 && PL_dowarn) - warn ("Can't %s \"%s\": %s",fl ? "exec" : "spawn",prog,Strerror (errno)); - if (rc > 0) - return rc <<= 8; - if (rc < 0) - return 255 << 8; - return 0; + if (rc < 0 && ckWARN(WARN_EXEC)) + Perl_warner(aTHX_ WARN_EXEC,"Can't %s \"%s\": %s", + fl ? "exec" : "spawn",prog,Strerror (errno)); + if (rc >= 0) + return rc << 8; + return -1; } int -do_aspawn (SV *really,SV **mark,SV **sp) +do_aspawn (pTHX_ SV *really,SV **mark,SV **sp) { - dTHR; int rc; char **a,*tmps,**argv; + STRLEN n_a; if (sp<=mark) return -1; @@ -141,7 +126,7 @@ do_aspawn (SV *really,SV **mark,SV **sp) while (++mark <= sp) if (*mark) - *a++ = SvPVx(*mark, PL_na); + *a++ = SvPVx(*mark, n_a); else *a++ = ""; *a = Nullch; @@ -152,7 +137,7 @@ do_aspawn (SV *really,SV **mark,SV **sp) ) /* will swawnvp use PATH? */ TAINT_ENV(); /* testing IFS here is overkill, probably */ - if (really && *(tmps = SvPV(really, PL_na))) + if (really && *(tmps = SvPV(really, n_a))) rc=spawnvp (P_WAIT,tmps,argv); else rc=spawnvp (P_WAIT,argv[0],argv); @@ -163,7 +148,7 @@ do_aspawn (SV *really,SV **mark,SV **sp) #define EXTRA "\x00\x00\x00\x00\x00\x00" int -do_spawn2 (char *cmd,int execf) +do_spawn2 (pTHX_ char *cmd,int execf) { char **a,*s,*shell,*metachars; int rc,unixysh; @@ -231,15 +216,15 @@ doshell: } int -do_spawn (char *cmd) +do_spawn (pTHX_ char *cmd) { - return do_spawn2 (cmd,EXECF_SPAWN); + return do_spawn2 (aTHX_ cmd,EXECF_SPAWN); } bool -do_exec (char *cmd) +Perl_do_exec (pTHX_ char *cmd) { - do_spawn2 (cmd,EXECF_EXEC); + do_spawn2 (aTHX_ cmd,EXECF_EXEC); return FALSE; } @@ -250,6 +235,7 @@ struct globinfo int fd; char *matches; size_t size; + fpos_t pos; }; #define MAXOPENGLOBS 10 @@ -284,6 +270,7 @@ glob_handler (__FSEXT_Fnumber n,int *rv,va_list args) if ((gi=searchfd (-1)) == NULL) break; + gi->pos=0; pattern=alloca (strlen (name+=13)+1); strcpy (pattern,name); if (!_USE_LFN) @@ -330,11 +317,10 @@ glob_handler (__FSEXT_Fnumber n,int *rv,va_list args) if ((gi=searchfd (fd))==NULL) break; - ic=tell (fd); - if (siz+ic>=gi->size) - siz=gi->size-ic; - memcpy (buf,ic+gi->matches,siz); - lseek (fd,siz,1); + if (siz+gi->pos > gi->size) + siz = gi->size - gi->pos; + memcpy (buf,gi->pos+gi->matches,siz); + gi->pos += siz; *rv=siz; return 1; } @@ -360,12 +346,15 @@ XS(dos_GetCwd) dXSARGS; if (items) - croak ("Usage: Dos::GetCwd()"); + Perl_croak (aTHX_ "Usage: Dos::GetCwd()"); { char tmp[PATH_MAX+2]; ST(0)=sv_newmortal (); if (getcwd (tmp,PATH_MAX+1)!=NULL) sv_setpv ((SV*)ST(0),tmp); +#ifndef INCOMPLETE_TAINTS + SvTAINTED_on(ST(0)); +#endif } XSRETURN (1); } @@ -378,7 +367,7 @@ XS(dos_UseLFN) } void -init_os_extras() +Perl_init_os_extras(pTHX) { char *file = __FILE__; @@ -396,7 +385,8 @@ static char *perlprefix; #define PERL5 "/perl5" -char *djgpp_pathexp (const char *p) +char * +djgpp_pathexp (const char *p) { static char expp[PATH_MAX]; strcpy (expp,perlprefix); @@ -432,3 +422,22 @@ Perl_DJGPP_init (int *argcp,char ***argvp) strcpy (perlprefix,".."); } +int +djgpp_fflush (FILE *fp) +{ + int res; + + if ((res = fflush(fp)) == 0 && fp) { + Stat_t s; + if (Fstat(fileno(fp), &s) == 0 && !S_ISSOCK(s.st_mode)) + res = fsync(fileno(fp)); + } +/* + * If the flush succeeded but set end-of-file, we need to clear + * the error because our caller may check ferror(). BTW, this + * probably means we just flushed an empty file. + */ + if (res == 0 && fp && ferror(fp) == EOF) clearerr(fp); + + return res; +}