summaryrefslogtreecommitdiff
path: root/pp_sys.c
diff options
context:
space:
mode:
authorNicholas Clark <nick@ccl4.org>2005-11-04 13:02:42 +0000
committerNicholas Clark <nick@ccl4.org>2005-11-04 13:02:42 +0000
commitaf9e49b40a4cc2d6c0d5ebad7e84fb62143b24e1 (patch)
tree416d37161f75757de3100eee573d3cdf9c53c516 /pp_sys.c
parent70cf0185be8a46ed25b37689143a5eb26c7909eb (diff)
downloadperl-af9e49b40a4cc2d6c0d5ebad7e84fb62143b24e1.tar.gz
ftrwrite, ftrexec, fteread, ftewrite and fteexec can all be merged
with Perl_pp_ftrread(). p4raw-id: //depot/perl@25986
Diffstat (limited to 'pp_sys.c')
-rw-r--r--pp_sys.c199
1 files changed, 74 insertions, 125 deletions
diff --git a/pp_sys.c b/pp_sys.c
index ff8254adb8..9b08cac328 100644
--- a/pp_sys.c
+++ b/pp_sys.c
@@ -2873,161 +2873,110 @@ PP(pp_stat)
PP(pp_ftrread)
{
I32 result;
- dSP;
- STACKED_FTEST_CHECK;
-#if defined(HAS_ACCESS) && defined(R_OK)
- if ((PL_op->op_private & OPpFT_ACCESS) && SvPOK(TOPs)) {
- result = access(POPpx, R_OK);
- if (result == 0)
- RETPUSHYES;
- if (result < 0)
- RETPUSHUNDEF;
- RETPUSHNO;
- }
- else
- result = my_stat();
+ /* Not const, because things tweak this below. Not bool, because there's
+ no guarantee that OPp_FT_ACCESS is <= CHAR_MAX */
+#if defined(HAS_ACCESS) || defined (PERL_EFF_ACCESS)
+ I32 use_access = PL_op->op_private & OPpFT_ACCESS;
+ /* Giving some sort of initial value silences compilers. */
+# ifdef R_OK
+ int access_mode = R_OK;
+# else
+ int access_mode = 0;
+# endif
#else
- result = my_stat();
+ /* access_mode is never used, but leaving use_access in makes the
+ conditional compiling below much clearer. */
+ I32 use_access = 0;
#endif
- SPAGAIN;
- if (result < 0)
- RETPUSHUNDEF;
- if (cando(S_IRUSR, 0, &PL_statcache))
- RETPUSHYES;
- RETPUSHNO;
-}
+ int stat_mode = S_IRUSR;
-PP(pp_ftrwrite)
-{
- I32 result;
+ bool effective = FALSE;
dSP;
+
STACKED_FTEST_CHECK;
+
+ switch (PL_op->op_type) {
+ case OP_FTRREAD:
+#if !(defined(HAS_ACCESS) && defined(R_OK))
+ use_access = 0;
+#endif
+ break;
+
+ case OP_FTRWRITE:
#if defined(HAS_ACCESS) && defined(W_OK)
- if ((PL_op->op_private & OPpFT_ACCESS) && SvPOK(TOPs)) {
- result = access(POPpx, W_OK);
- if (result == 0)
- RETPUSHYES;
- if (result < 0)
- RETPUSHUNDEF;
- RETPUSHNO;
- }
- else
- result = my_stat();
+ access_mode = W_OK;
#else
- result = my_stat();
+ use_access = 0;
#endif
- SPAGAIN;
- if (result < 0)
- RETPUSHUNDEF;
- if (cando(S_IWUSR, 0, &PL_statcache))
- RETPUSHYES;
- RETPUSHNO;
-}
+ stat_mode = S_IWUSR;
+ break;
-PP(pp_ftrexec)
-{
- I32 result;
- dSP;
- STACKED_FTEST_CHECK;
+ case OP_FTREXEC:
#if defined(HAS_ACCESS) && defined(X_OK)
- if ((PL_op->op_private & OPpFT_ACCESS) && SvPOK(TOPs)) {
- result = access(POPpx, X_OK);
- if (result == 0)
- RETPUSHYES;
- if (result < 0)
- RETPUSHUNDEF;
- RETPUSHNO;
- }
- else
- result = my_stat();
+ access_mode = X_OK;
#else
- result = my_stat();
+ use_access = 0;
#endif
- SPAGAIN;
- if (result < 0)
- RETPUSHUNDEF;
- if (cando(S_IXUSR, 0, &PL_statcache))
- RETPUSHYES;
- RETPUSHNO;
-}
+ stat_mode = S_IXUSR;
+ break;
-PP(pp_fteread)
-{
- I32 result;
- dSP;
- STACKED_FTEST_CHECK;
+ case OP_FTEWRITE:
#ifdef PERL_EFF_ACCESS
- if ((PL_op->op_private & OPpFT_ACCESS) && SvPOK(TOPs)) {
- result = PERL_EFF_ACCESS(POPpx, R_OK);
- if (result == 0)
- RETPUSHYES;
- if (result < 0)
- RETPUSHUNDEF;
- RETPUSHNO;
- }
- else
- result = my_stat();
-#else
- result = my_stat();
+ access_mode = W_OK;
#endif
- SPAGAIN;
- if (result < 0)
- RETPUSHUNDEF;
- if (cando(S_IRUSR, 1, &PL_statcache))
- RETPUSHYES;
- RETPUSHNO;
-}
+ stat_mode = S_IWUSR;
+ /* Fall through */
-PP(pp_ftewrite)
-{
- I32 result;
- dSP;
- STACKED_FTEST_CHECK;
+ case OP_FTEREAD:
+#ifndef PERL_EFF_ACCESS
+ use_access = 0;
+#endif
+ effective = TRUE;
+ break;
+
+
+ case OP_FTEEXEC:
#ifdef PERL_EFF_ACCESS
- if ((PL_op->op_private & OPpFT_ACCESS) && SvPOK(TOPs)) {
- result = PERL_EFF_ACCESS(POPpx, W_OK);
- if (result == 0)
- RETPUSHYES;
- if (result < 0)
- RETPUSHUNDEF;
- RETPUSHNO;
- }
- else
- result = my_stat();
+ access_mode = W_OK;
#else
- result = my_stat();
+ use_access = 0;
#endif
- SPAGAIN;
- if (result < 0)
- RETPUSHUNDEF;
- if (cando(S_IWUSR, 1, &PL_statcache))
- RETPUSHYES;
- RETPUSHNO;
-}
+ stat_mode = S_IXUSR;
+ effective = TRUE;
+ break;
+ }
-PP(pp_fteexec)
-{
- I32 result;
- dSP;
- STACKED_FTEST_CHECK;
-#ifdef PERL_EFF_ACCESS
- if ((PL_op->op_private & OPpFT_ACCESS) && SvPOK(TOPs)) {
- result = PERL_EFF_ACCESS(POPpx, X_OK);
+ if (use_access) {
+#if defined(HAS_ACCESS) || defined (PERL_EFF_ACCESS)
+ const char *const name = POPpx;
+ if (effective) {
+# ifdef PERL_EFF_ACCESS
+ result = PERL_EFF_ACCESS(name, access_mode);
+# else
+ DIE(aTHX_ "panic: attempt to call PERL_EFF_ACCESS in %s",
+ OP_NAME(PL_op));
+# endif
+ }
+ else {
+# ifdef HAS_ACCESS
+ result = access(name, access_mode);
+# else
+ DIE(aTHX_ "panic: attempt to call access() in %s", OP_NAME(PL_op));
+# endif
+ }
if (result == 0)
RETPUSHYES;
if (result < 0)
RETPUSHUNDEF;
RETPUSHNO;
+#endif
}
- else
- result = my_stat();
-#else
+
result = my_stat();
-#endif
SPAGAIN;
if (result < 0)
RETPUSHUNDEF;
- if (cando(S_IXUSR, 1, &PL_statcache))
+ if (cando(stat_mode, effective, &PL_statcache))
RETPUSHYES;
RETPUSHNO;
}