diff options
author | Karl Williamson <khw@cpan.org> | 2017-03-09 10:55:38 -0700 |
---|---|---|
committer | Karl Williamson <khw@cpan.org> | 2017-11-06 12:50:05 -0700 |
commit | f55ac4a45513e50ae06769ee748ea079c9577a7f (patch) | |
tree | 663fe20c1c662cf29b46b6689d8d8b69f3125029 | |
parent | b59bf0b2884b21b6f3ce5eca607ab7a6096d87f5 (diff) | |
download | perl-f55ac4a45513e50ae06769ee748ea079c9577a7f.tar.gz |
Change some strncmp(), etc. to strBEGINs()
The latter is much clearer as to what's going on, and the programmer and
program reader don't have to count characters.
-rw-r--r-- | cygwin/cygwin.c | 4 | ||||
-rw-r--r-- | djgpp/djgpp.c | 6 | ||||
-rw-r--r-- | ext/VMS-Stdio/Stdio.pm | 2 | ||||
-rw-r--r-- | ext/VMS-Stdio/Stdio.xs | 2 | ||||
-rw-r--r-- | ext/XS-APItest/APItest.xs | 9 | ||||
-rw-r--r-- | op.c | 2 | ||||
-rw-r--r-- | perl.c | 6 | ||||
-rw-r--r-- | pp.c | 2 | ||||
-rw-r--r-- | pp_ctl.c | 2 | ||||
-rw-r--r-- | pp_pack.c | 2 | ||||
-rw-r--r-- | regcomp.c | 4 | ||||
-rw-r--r-- | toke.c | 2 | ||||
-rw-r--r-- | vms/vms.c | 18 | ||||
-rw-r--r-- | win32/win32.c | 2 |
14 files changed, 30 insertions, 33 deletions
diff --git a/cygwin/cygwin.c b/cygwin/cygwin.c index 7bcf02ab34..a234825eba 100644 --- a/cygwin/cygwin.c +++ b/cygwin/cygwin.c @@ -98,7 +98,7 @@ do_spawn (char *cmd) while (*cmd && isSPACE(*cmd)) cmd++; - if (strnEQ (cmd,"/bin/sh",7) && isSPACE (cmd[7])) + if (strBEGINs (cmd,"/bin/sh") && isSPACE (cmd[7])) cmd+=5; /* save an extra exec if possible */ @@ -107,7 +107,7 @@ do_spawn (char *cmd) goto doshell; if (*cmd=='.' && isSPACE (cmd[1])) goto doshell; - if (strnEQ (cmd,"exec",4) && isSPACE (cmd[4])) + if (strBEGINs (cmd,"exec") && isSPACE (cmd[4])) goto doshell; for (s=cmd; *s && isALPHA (*s); s++) ; /* catch VAR=val gizmo */ if (*s=='=') diff --git a/djgpp/djgpp.c b/djgpp/djgpp.c index 6d136e38bb..d1c09aad67 100644 --- a/djgpp/djgpp.c +++ b/djgpp/djgpp.c @@ -162,7 +162,7 @@ do_spawn2 (pTHX_ char *cmd,int execf) while (*cmd && isSPACE(*cmd)) cmd++; - if (strnEQ (cmd,"/bin/sh",7) && isSPACE (cmd[7])) + if (strBEGINs (cmd,"/bin/sh") && isSPACE (cmd[7])) cmd+=5; /* save an extra exec if possible */ @@ -173,7 +173,7 @@ do_spawn2 (pTHX_ char *cmd,int execf) { if (*cmd=='.' && isSPACE (cmd[1])) goto doshell; - if (strnEQ (cmd,"exec",4) && isSPACE (cmd[4])) + if (strBEGINs (cmd,"exec") && isSPACE (cmd[4])) goto doshell; for (s=cmd; *s && isALPHA (*s); s++) ; /* catch VAR=val gizmo */ if (*s=='=') @@ -265,7 +265,7 @@ glob_handler (__FSEXT_Fnumber n,int *rv,va_list args) STRLEN len; glob_t pglob; - if (strnNE (name,"/dev/dosglob/",13)) + if (! strBEGINs (name,"/dev/dosglob/")) break; if ((gi=searchfd (-1)) == NULL) break; diff --git a/ext/VMS-Stdio/Stdio.pm b/ext/VMS-Stdio/Stdio.pm index f9ed211d3b..e692e05b08 100644 --- a/ext/VMS-Stdio/Stdio.pm +++ b/ext/VMS-Stdio/Stdio.pm @@ -13,7 +13,7 @@ use Carp '&croak'; use DynaLoader (); use Exporter (); -$VERSION = '2.42'; +$VERSION = '2.43'; @ISA = qw( Exporter DynaLoader IO::File ); @EXPORT = qw( &O_APPEND &O_CREAT &O_EXCL &O_NDELAY &O_NOWAIT &O_RDONLY &O_RDWR &O_TRUNC &O_WRONLY ); diff --git a/ext/VMS-Stdio/Stdio.xs b/ext/VMS-Stdio/Stdio.xs index 144f9370cc..1e96cdb9c6 100644 --- a/ext/VMS-Stdio/Stdio.xs +++ b/ext/VMS-Stdio/Stdio.xs @@ -15,7 +15,7 @@ static bool constant(char *name, IV *pval) { - if (strnNE(name, "O_", 2)) return FALSE; + if (! strBEGINs(name, "O_")) return FALSE; if (strEQ(name, "O_APPEND")) #ifdef O_APPEND diff --git a/ext/XS-APItest/APItest.xs b/ext/XS-APItest/APItest.xs index fa11b05fdc..5dc1b27635 100644 --- a/ext/XS-APItest/APItest.xs +++ b/ext/XS-APItest/APItest.xs @@ -2346,8 +2346,7 @@ CODE: SP -= retcnt; errsv = ERRSV; errstr = SvPV_nolen(errsv); - if(strnEQ(errstr, "Undefined subroutine &main:: called at", - sizeof("Undefined subroutine &main:: called at") - 1)) { + if(strBEGINs(errstr, "Undefined subroutine &main:: called at")) { PUSHMARK(SP); retcnt = call_sv((SV*)i_sub, 0); /* call again to increase counter */ SPAGAIN; @@ -2359,8 +2358,7 @@ CODE: SP -= retcnt; errsv = ERRSV; errstr = SvPV_nolen(errsv); - if(strnEQ(errstr, "Can't use an undefined value as a subroutine reference at", - sizeof("Can't use an undefined value as a subroutine reference at") - 1)) { + if(strBEGINs(errstr, "Can't use an undefined value as a subroutine reference at")) { PUSHMARK(SP); retcnt = call_sv((SV*)i_sub, 0); /* call again to increase counter */ SPAGAIN; @@ -2372,8 +2370,7 @@ CODE: SP -= retcnt; errsv = ERRSV; errstr = SvPV_nolen(errsv); - if(strnEQ(errstr, "Not a CODE reference at", - sizeof("Not a CODE reference at") - 1)) { + if(strBEGINs(errstr, "Not a CODE reference at")) { PUSHMARK(SP); retcnt = call_sv((SV*)i_sub, 0); /* call again to increase counter */ SPAGAIN; @@ -11831,7 +11831,7 @@ Perl_ck_method(pTHX_ OP *o) } /* $proto->MyClass::method() and $proto->MyClass::SUPER::method() */ - if (nsplit >= 9 && strnEQ(method+nsplit-9, "::SUPER::", 9)) { + if (nsplit >= 9 && strBEGINs(method+nsplit-9, "::SUPER::")) { rclass = newSVpvn_share(method, utf8*(nsplit-9), 0); new_op = newMETHOP_named(OP_METHOD_REDIR_SUPER, 0, methsv); } else { @@ -3921,9 +3921,9 @@ S_open_script(pTHX_ const char *scriptname, bool dosearch, bool *suidscript) #endif rsfp = PerlIO_open(scriptname,PERL_SCRIPT_MODE); #ifdef FAKE_BIT_BUCKET - if (memEQ(scriptname, FAKE_BIT_BUCKET_PREFIX, - sizeof(FAKE_BIT_BUCKET_PREFIX) - 1) - && strlen(scriptname) == sizeof(tmpname) - 1) { + if ( strBEGINs(scriptname, FAKE_BIT_BUCKET_PREFIX) + && strlen(scriptname) == sizeof(tmpname) - 1) + { unlink(scriptname); } scriptname = BIT_BUCKET; @@ -384,7 +384,7 @@ PP(pp_prototype) if (SvGMAGICAL(TOPs)) SETs(sv_mortalcopy(TOPs)); if (SvPOK(TOPs) && SvCUR(TOPs) >= 7) { const char * s = SvPVX_const(TOPs); - if (strnEQ(s, "CORE::", 6)) { + if (strBEGINs(s, "CORE::")) { const int code = keyword(s + 6, SvCUR(TOPs) - 6, 1); if (!code) DIE(aTHX_ "Can't find an opnumber for \"%" UTF8f "\"", @@ -916,7 +916,7 @@ PP(pp_formline) *t++ = ' '; } s1 = t - 3; - if (strnEQ(s1," ",3)) { + if (strBEGINs(s1," ")) { while (s1 > SvPVX_const(PL_formtarget) && isSPACE(s1[-1])) s1--; } @@ -191,7 +191,7 @@ S_mul128(pTHX_ SV *sv, U8 m) PERL_ARGS_ASSERT_MUL128; - if (!strnEQ(s, "0000", 4)) { /* need to grow sv */ + if (! strBEGINs(s, "0000")) { /* need to grow sv */ SV * const tmpNew = newSVpvs("0000000000"); sv_catsv(tmpNew, sv); @@ -12061,8 +12061,8 @@ S_grok_bslash_N(pTHX_ RExC_state_t *pRExC_state, } else if(!(endbrace == RExC_parse /* nothing between the {} */ || (endbrace - RExC_parse >= 2 /* U+ (bad hex is checked... */ - && strnEQ(RExC_parse, "U+", 2)))) /* ... below for a better - error msg) */ + && strBEGINs(RExC_parse, "U+")))) /* ... below for a better + error msg) */ { RExC_parse = endbrace; /* position msg's '<--HERE' */ vFAIL("\\N{NAME} must be resolved by the lexer"); @@ -4877,7 +4877,7 @@ Perl_yylex(pTHX) } else { I32 tmp; - if (strnEQ(s, "L\\u", 3) || strnEQ(s, "U\\l", 3)) + if (strBEGINs(s, "L\\u") || strBEGINs(s, "U\\l")) tmp = *s, *s = s[2], s[2] = (char)tmp; /* misordered... */ if ((*s == 'L' || *s == 'U' || *s == 'F') && (strpbrk(PL_lex_casestack, "LUF"))) @@ -285,7 +285,7 @@ is_unix_filespec(const char *path) const char * pch1; ret_val = 0; - if (strncmp(path,"\"^UP^",5) != 0) { + if (! strBEGINs(path,"\"^UP^")) { pch1 = strchr(path, '/'); if (pch1 != NULL) ret_val = 1; @@ -6427,7 +6427,7 @@ int_fileify_dirspec(const char *dir, char *buf, int *utf8_fl) if (!cp1) cp1 = strstr(my_esa,"]<"); dirlen = cp1 - my_esa; memcpy(buf, my_esa, dirlen); - if (!strncmp(cp1+2,"000000]",7)) { + if (strBEGINs(cp1+2,"000000]")) { buf[dirlen-1] = '\0'; /* fix-me Not full ODS-5, just extra dots in directories for now */ cp1 = buf + dirlen - 1; @@ -7032,7 +7032,7 @@ int_tounixspec(const char *spec, char *rslt, int * utf8_fl) * glob passes filenames with trailing '\n' and expects this preserved. */ if (decc_posix_compliant_pathnames) { - if (strncmp(spec, "\"^UP^", 5) == 0) { + if (! strBEGINs(spec, "\"^UP^")) { char * uspec; char *tunix; int tunix_len; @@ -7463,7 +7463,7 @@ posix_root_to_vms(char *vmspath, int vmspath_len, #if __CRTL_VER >= 80200000 /* If not a posix spec already, convert it */ if (decc_posix_compliant_pathnames) { - if (strncmp(unixpath,"\"^UP^",5) != 0) { + if (! strBEGINs(unixpath,"\"^UP^")) { sprintf(vmspath,"\"^UP^%s\"",unixpath); } else { @@ -7578,7 +7578,7 @@ posix_root_to_vms(char *vmspath, int vmspath_len, /* on any failure, returned the POSIX ^UP^ filespec */ if (!(sts & 1)) { /* This can happen if user does not have permission to read directories */ - if (strncmp(unixpath,"\"^UP^",5) != 0) + if (! strBEGINs(unixpath,"\"^UP^")) sprintf(vmspath,"\"^UP^%s\"",unixpath); else my_strlcpy(vmspath, unixpath, vmspath_len + 1); @@ -7717,7 +7717,7 @@ posix_to_vmsspec_hardway(char *vmspath, int vmspath_len, const char *unixpath, quoted = 0; /* This could have a "^UP^ on the front */ - if (strncmp(unixptr,"\"^UP^",5) == 0) { + if (strBEGINs(unixptr,"\"^UP^")) { quoted = 1; unixptr+= 5; unixlen-= 5; @@ -8435,7 +8435,7 @@ int_tovmsspec(const char *path, char *rslt, int dir_flag, int * utf8_flag) /*--------------------------------------------------*/ #if __CRTL_VER >= 80200000 if (decc_posix_compliant_pathnames) { - if (strncmp(path,"\"^UP^",5) == 0) { + if (strBEGINs(path,"\"^UP^")) { posix_to_vmsspec_hardway(rslt, rslt_len, path, dir_flag, utf8_flag); return rslt; } @@ -8576,7 +8576,7 @@ int_tovmsspec(const char *path, char *rslt, int dir_flag, int * utf8_flag) islnm = simple_trnlnm(rslt,trndev,VMS_MAXRSS-1); } else if (strEQ(rslt,"dev")) { - if (strncmp(cp2,"/null", 5) == 0) { + if (strBEGINs(cp2,"/null")) { if ((cp2[5] == 0) || (cp2[5] == '/')) { strcpy(rslt,"NLA0"); cp1 = rslt + 4; @@ -11838,7 +11838,7 @@ static int is_null_device(const char *name) { if (decc_bug_devnull != 0) { - if (strncmp("/dev/null", name, 9) == 0) + if (strBEGINs(name, "/dev/null")) return 1; } /* The VMS null device is named "_NLA0:", usually abbreviated as "NL:". diff --git a/win32/win32.c b/win32/win32.c index f41ce6db8c..89522abaca 100644 --- a/win32/win32.c +++ b/win32/win32.c @@ -1849,7 +1849,7 @@ win32_getenv(const char *name) else { /* last ditch: allow any environment variables that begin with 'PERL' to be obtained from the registry, if found there */ - if (strncmp(name, "PERL", 4) == 0) + if (strBEGINs(name, "PERL")) (void)get_regstr(name, &curitem); } #endif |