diff options
author | Nicholas Clark <nick@ccl4.org> | 2014-03-02 07:38:00 +0100 |
---|---|---|
committer | Nicholas Clark <nick@ccl4.org> | 2014-03-19 10:57:52 +0100 |
commit | a2b41d5ca668b3be2860093f464392277e1d0034 (patch) | |
tree | f265d7bfcd77d643052a6fb7ce58153c1b042e45 | |
parent | b4464d55c8c3facb333bef167fb547bff86d55ae (diff) | |
download | perl-a2b41d5ca668b3be2860093f464392277e1d0034.tar.gz |
Extract the setup code of Perl_do_openn() into S_openn_setup().
-rw-r--r-- | doio.c | 54 | ||||
-rw-r--r-- | embed.fnc | 5 | ||||
-rw-r--r-- | embed.h | 1 | ||||
-rw-r--r-- | proto.h | 10 |
4 files changed, 51 insertions, 19 deletions
@@ -60,25 +60,19 @@ #include <signal.h> -bool -Perl_do_openn(pTHX_ GV *gv, const char *oname, I32 len, int as_raw, - int rawmode, int rawperm, PerlIO *supplied_fp, SV **svp, - I32 num_svs) +static IO * +S_openn_setup(pTHX_ GV *gv, char *mode, PerlIO **saveifp, PerlIO **saveofp, + int *savefd, char *savetype) { dVAR; IO * const io = GvIOn(gv); - PerlIO *saveifp = NULL; - PerlIO *saveofp = NULL; - int savefd = -1; - char savetype = IoTYPE_CLOSED; - int writing = 0; - PerlIO *fp; - int fd; - bool was_fdopen = FALSE; - char *type = NULL; - char mode[PERL_MODE_MAX]; /* file mode ("r\0", "rb\0", "ab\0" etc.) */ - PERL_ARGS_ASSERT_DO_OPENN; + PERL_ARGS_ASSERT_OPENN_SETUP; + + *saveifp = NULL; + *saveofp = NULL; + *savefd = -1; + *savetype = IoTYPE_CLOSED; Zero(mode,sizeof(mode),char); PL_forkprocess = 1; /* assume true if no fork */ @@ -93,10 +87,10 @@ Perl_do_openn(pTHX_ GV *gv, const char *oname, I32 len, int as_raw, if (old_fd >= 0 && old_fd <= PL_maxsysfd) { /* This is one of the original STD* handles */ - saveifp = IoIFP(io); - saveofp = IoOFP(io); - savetype = IoTYPE(io); - savefd = old_fd; + *saveifp = IoIFP(io); + *saveofp = IoOFP(io); + *savetype = IoTYPE(io); + *savefd = old_fd; } else { int result; @@ -125,6 +119,28 @@ Perl_do_openn(pTHX_ GV *gv, const char *oname, I32 len, int as_raw, } IoOFP(io) = IoIFP(io) = NULL; } + return io; +} + +bool +Perl_do_openn(pTHX_ GV *gv, const char *oname, I32 len, int as_raw, + int rawmode, int rawperm, PerlIO *supplied_fp, SV **svp, + I32 num_svs) +{ + dVAR; + PerlIO *saveifp; + PerlIO *saveofp; + int savefd; + char savetype; + char mode[PERL_MODE_MAX]; /* file mode ("r\0", "rb\0", "ab\0" etc.) */ + IO * const io = openn_setup(gv, mode, &saveifp, &saveofp, &savefd, &savetype); + int writing = 0; + PerlIO *fp; + int fd; + bool was_fdopen = FALSE; + char *type = NULL; + + PERL_ARGS_ASSERT_DO_OPENN; if (as_raw) { /* sysopen style args, i.e. integer mode and permissions */ @@ -394,6 +394,11 @@ Apmb |bool |do_open |NN GV* gv|NN const char* name|I32 len|int as_raw \ Ap |bool |do_open9 |NN GV *gv|NN const char *name|I32 len|int as_raw \ |int rawmode|int rawperm|NULLOK PerlIO *supplied_fp \ |NN SV *svs|I32 num +#if defined(PERL_IN_DOIO_C) +s |IO * |openn_setup |NN GV *gv|NN char *mode|NN PerlIO **saveifp \ + |NN PerlIO **saveofp|NN int *savefd \ + |NN char *savetype +#endif Ap |bool |do_openn |NN GV *gv|NN const char *oname|I32 len \ |int as_raw|int rawmode|int rawperm \ |NULLOK PerlIO *supplied_fp|NULLOK SV **svp \ @@ -1383,6 +1383,7 @@ # if defined(PERL_IN_DOIO_C) #define exec_failed(a,b,c) S_exec_failed(aTHX_ a,b,c) #define ingroup(a,b) S_ingroup(aTHX_ a,b) +#define openn_setup(a,b,c,d,e,f) S_openn_setup(aTHX_ a,b,c,d,e,f) # endif # if defined(PERL_IN_DOOP_C) #define do_trans_complex(a) S_do_trans_complex(aTHX_ a) @@ -5712,6 +5712,16 @@ STATIC void S_exec_failed(pTHX_ const char *cmd, int fd, int do_report) STATIC bool S_ingroup(pTHX_ Gid_t testgid, bool effective) __attribute__warn_unused_result__; +STATIC IO * S_openn_setup(pTHX_ GV *gv, char *mode, PerlIO **saveifp, PerlIO **saveofp, int *savefd, char *savetype) + __attribute__nonnull__(pTHX_1) + __attribute__nonnull__(pTHX_2) + __attribute__nonnull__(pTHX_3) + __attribute__nonnull__(pTHX_4) + __attribute__nonnull__(pTHX_5) + __attribute__nonnull__(pTHX_6); +#define PERL_ARGS_ASSERT_OPENN_SETUP \ + assert(gv); assert(mode); assert(saveifp); assert(saveofp); assert(savefd); assert(savetype) + #endif #if defined(PERL_IN_DOOP_C) STATIC I32 S_do_trans_complex(pTHX_ SV * const sv) |