diff options
author | Tony Cook <tony@develop-help.com> | 2014-05-12 13:55:36 +1000 |
---|---|---|
committer | Tony Cook <tony@develop-help.com> | 2014-05-28 10:31:12 +1000 |
commit | 7cb3f9598b37fcd8b30ea273d668c8b48d5f4c76 (patch) | |
tree | 3a1635f819dcc4eb6a2869ba1166d63b899759c4 /inline.h | |
parent | 4ac9c666a62d8b538b58e38bb7539c40ca7ffb9b (diff) | |
download | perl-7cb3f9598b37fcd8b30ea273d668c8b48d5f4c76.tar.gz |
[perl #121112] only warn if newline is the last non-NUL character
Diffstat (limited to 'inline.h')
-rw-r--r-- | inline.h | 32 |
1 files changed, 32 insertions, 0 deletions
@@ -323,6 +323,38 @@ S_is_safe_syscall(pTHX_ const char *pv, STRLEN len, const char *what, const char } /* + +Return true if the supplied filename has a newline character +immediately before the final NUL. + +My original look at this incorrectly used the len from SvPV(), but +that's incorrect, since we allow for a NUL in pv[len-1]. + +So instead, strlen() and work from there. + +This allow for the user reading a filename, forgetting to chomp it, +then calling: + + open my $foo, "$file\0"; + +*/ + +#ifdef PERL_CORE + +PERL_STATIC_INLINE bool +S_should_warn_nl(const char *pv) { + STRLEN len; + + PERL_ARGS_ASSERT_SHOULD_WARN_NL; + + len = strlen(pv); + + return len > 0 && pv[len-1] == '\n'; +} + +#endif + +/* * Local variables: * c-indentation-style: bsd * c-basic-offset: 4 |