summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doio.c10
-rw-r--r--mg.c8
-rw-r--r--perl.h10
-rw-r--r--perlio.c10
-rw-r--r--pp_sys.c8
-rw-r--r--sv.c4
-rw-r--r--util.c27
-rw-r--r--vms/vms.c6
8 files changed, 43 insertions, 40 deletions
diff --git a/doio.c b/doio.c
index 09170188ec..5b41a78a10 100644
--- a/doio.c
+++ b/doio.c
@@ -663,9 +663,9 @@ Perl_do_openn(pTHX_ GV *gv, register const char *oname, I32 len, int as_raw,
}
#if defined(HAS_FCNTL) && defined(F_SETFD)
if (fd >= 0) {
- const int save_errno = errno;
+ dSAVE_ERRNO;
fcntl(fd,F_SETFD,fd > PL_maxsysfd); /* can change errno */
- errno = save_errno;
+ RESTORE_ERRNO;
}
#endif
IoIFP(io) = fp;
@@ -1014,14 +1014,14 @@ Perl_do_eof(pTHX_ GV *gv)
{
/* getc and ungetc can stomp on errno */
- const int saverrno = errno;
+ dSAVE_ERRNO;
const int ch = PerlIO_getc(IoIFP(io));
if (ch != EOF) {
(void)PerlIO_ungetc(IoIFP(io),ch);
- errno = saverrno;
+ RESTORE_ERRNO;
return FALSE;
}
- errno = saverrno;
+ RESTORE_ERRNO;
}
if (PerlIO_has_cntptr(IoIFP(io)) && PerlIO_canset_cnt(IoIFP(io))) {
diff --git a/mg.c b/mg.c
index 6f4cc5805b..7acff5190f 100644
--- a/mg.c
+++ b/mg.c
@@ -817,10 +817,10 @@ Perl_magic_get(pTHX_ SV *sv, MAGIC *mg)
}
#else
{
- const int saveerrno = errno;
+ dSAVE_ERRNO;
sv_setnv(sv, (NV)errno);
sv_setpv(sv, errno ? Strerror(errno) : "");
- errno = saveerrno;
+ RESTORE_ERRNO;
}
#endif
SvRTRIM(sv);
@@ -1036,7 +1036,7 @@ Perl_magic_get(pTHX_ SV *sv, MAGIC *mg)
sv_setpv(sv, errno ? Strerror(errno) : "");
#else
{
- const int saveerrno = errno;
+ dSAVE_ERRNO;
sv_setnv(sv, (NV)errno);
#ifdef OS2
if (errno == errno_isOS2 || errno == errno_isOS2_set)
@@ -1044,7 +1044,7 @@ Perl_magic_get(pTHX_ SV *sv, MAGIC *mg)
else
#endif
sv_setpv(sv, errno ? Strerror(errno) : "");
- errno = saveerrno;
+ RESTORE_ERRNO;
}
#endif
SvRTRIM(sv);
diff --git a/perl.h b/perl.h
index d91392911b..7d22338616 100644
--- a/perl.h
+++ b/perl.h
@@ -1277,6 +1277,11 @@ EXTERN_C char *crypt(const char *, const char *);
set_errno(errcode); \
set_vaxc_errno(vmserrcode); \
} STMT_END
+# define dSAVEDERRNO int saved_errno; unsigned saved_vms_errno
+# define dSAVE_ERRNO int saved_errno = errno; unsigned saved_vms_errno = vaxc$errno
+# define SAVE_ERRNO ( saved_errno = errno, saved_vms_errno = vaxc$errno )
+# define RESTORE_ERRNO SETERRNO(saved_errno, saved_vms_errno)
+
# define LIB_INVARG LIB$_INVARG
# define RMS_DIR RMS$_DIR
# define RMS_FAC RMS$_FAC
@@ -1291,6 +1296,11 @@ EXTERN_C char *crypt(const char *, const char *);
# define SS_NORMAL SS$_NORMAL
#else
# define SETERRNO(errcode,vmserrcode) (errno = (errcode))
+# define dSAVEDERRNO int saved_errno
+# define dSAVE_ERRNO int saved_errno = errno
+# define SAVE_ERRNO (saved_errno = errno)
+# define RESTORE_ERRNO (errno = saved_errno)
+
# define LIB_INVARG 0
# define RMS_DIR 0
# define RMS_FAC 0
diff --git a/perlio.c b/perlio.c
index a3ea344620..95c3b24fb7 100644
--- a/perlio.c
+++ b/perlio.c
@@ -3131,8 +3131,8 @@ PerlIOStdio_close(pTHX_ PerlIO *f)
const int fd = fileno(stdio);
int invalidate = 0;
IV result = 0;
- int saveerr = 0;
int dupfd = -1;
+ dSAVEDERRNO;
#ifdef USE_ITHREADS
dVAR;
#endif
@@ -3166,7 +3166,7 @@ PerlIOStdio_close(pTHX_ PerlIO *f)
fileno slot of the FILE *
*/
result = PerlIO_flush(f);
- saveerr = errno;
+ SAVE_ERRNO;
invalidate = PerlIOStdio_invalidate_fileno(aTHX_ stdio);
if (!invalidate) {
#ifdef USE_ITHREADS
@@ -3205,7 +3205,7 @@ PerlIOStdio_close(pTHX_ PerlIO *f)
errno may NOT be expected EBADF
*/
if (invalidate && result != 0) {
- errno = saveerr;
+ RESTORE_ERRNO;
result = 0;
}
#ifdef SOCKS5_VERSION_NAME
@@ -3367,9 +3367,9 @@ PerlIOStdio_flush(pTHX_ PerlIO *f)
/*
* Not writeable - sync by attempting a seek
*/
- const int err = errno;
+ dSAVE_ERRNO;
if (PerlSIO_fseek(stdio, (Off_t) 0, SEEK_CUR) != 0)
- errno = err;
+ RESTORE_ERRNO;
#endif
}
return 0;
diff --git a/pp_sys.c b/pp_sys.c
index 192ce6c01e..f1015ad5c2 100644
--- a/pp_sys.c
+++ b/pp_sys.c
@@ -5178,13 +5178,13 @@ PP(pp_gpwent)
* has a different API than the Solaris/IRIX one. */
# if defined(HAS_GETSPNAM) && !defined(_AIX)
{
- const int saverrno = errno;
+ dSAVE_ERRNO;
const struct spwd * const spwent = getspnam(pwent->pw_name);
/* Save and restore errno so that
* underprivileged attempts seem
* to have never made the unsccessful
* attempt to retrieve the shadow password. */
- errno = saverrno;
+ RESTORE_ERRNO;
if (spwent && spwent->sp_pwdp)
sv_setpv(sv, spwent->sp_pwdp);
}
@@ -5562,15 +5562,15 @@ static int
lockf_emulate_flock(int fd, int operation)
{
int i;
- const int save_errno = errno;
Off_t pos;
+ dSAVE_ERRNO;
/* flock locks entire file so for lockf we need to do the same */
pos = PerlLIO_lseek(fd, (Off_t)0, SEEK_CUR); /* get pos to restore later */
if (pos > 0) /* is seekable and needs to be repositioned */
if (PerlLIO_lseek(fd, (Off_t)0, SEEK_SET) < 0)
pos = -1; /* seek failed, so don't seek back afterwards */
- errno = save_errno;
+ RESTORE_ERRNO;
switch (operation) {
diff --git a/sv.c b/sv.c
index 7d6c041a60..9fe0a3f70d 100644
--- a/sv.c
+++ b/sv.c
@@ -2958,7 +2958,7 @@ Perl_sv_2pv_flags(pTHX_ register SV *const sv, STRLEN *const lp, const I32 flags
*s = '\0';
}
else if (SvNOKp(sv)) {
- const int olderrno = errno;
+ dSAVE_ERRNO;
if (SvTYPE(sv) < SVt_PVNV)
sv_upgrade(sv, SVt_PVNV);
/* The +20 is pure guesswork. Configure test needed. --jhi */
@@ -2972,7 +2972,7 @@ Perl_sv_2pv_flags(pTHX_ register SV *const sv, STRLEN *const lp, const I32 flags
{
Gconvert(SvNVX(sv), NV_DIG, 0, s);
}
- errno = olderrno;
+ RESTORE_ERRNO;
#ifdef FIXNEGATIVEZERO
if (*s == '-' && s[1] == '0' && !s[2]) {
s[0] = '0';
diff --git a/util.c b/util.c
index ec7b479a97..6af4be308f 100644
--- a/util.c
+++ b/util.c
@@ -1271,14 +1271,14 @@ Perl_write_to_stderr(pTHX_ const char* message, int msglen)
else {
#ifdef USE_SFIO
/* SFIO can really mess with your errno */
- const int e = errno;
+ dSAVED_ERRNO;
#endif
PerlIO * const serr = Perl_error_log;
PERL_WRITE_MSG_TO_CONSOLE(serr, message, msglen);
(void)PerlIO_flush(serr);
#ifdef USE_SFIO
- errno = e;
+ RESTORE_ERRNO;
#endif
}
}
@@ -2862,10 +2862,7 @@ Perl_my_pclose(pTHX_ PerlIO *ptr)
Pid_t pid;
Pid_t pid2;
bool close_failed;
- int saved_errno = 0;
-#ifdef WIN32
- int saved_win32_errno;
-#endif
+ dSAVEDERRNO;
LOCK_FDPID_MUTEX;
svp = av_fetch(PL_fdpid,PerlIO_fileno(ptr),TRUE);
@@ -2878,12 +2875,8 @@ Perl_my_pclose(pTHX_ PerlIO *ptr)
return my_syspclose(ptr);
}
#endif
- if ((close_failed = (PerlIO_close(ptr) == EOF))) {
- saved_errno = errno;
-#ifdef WIN32
- saved_win32_errno = GetLastError();
-#endif
- }
+ if ((close_failed = (PerlIO_close(ptr) == EOF)))
+ SAVE_ERRNO;
#ifdef UTS
if(PerlProc_kill(pid, 0) < 0) { return(pid); } /* HOM 12/23/91 */
#endif
@@ -2901,7 +2894,7 @@ Perl_my_pclose(pTHX_ PerlIO *ptr)
rsignal_restore(SIGQUIT, &qstat);
#endif
if (close_failed) {
- SETERRNO(saved_errno, 0);
+ RESTORE_ERRNO;
return -1;
}
return(pid2 < 0 ? pid2 : status == 0 ? 0 : (errno = 0, status));
@@ -5052,12 +5045,12 @@ S_socketpair_udp (int fd[2]) {
errno = ECONNABORTED;
tidy_up_and_fail:
{
- const int save_errno = errno;
+ dSAVE_ERRNO;
if (sockets[0] != -1)
PerlLIO_close(sockets[0]);
if (sockets[1] != -1)
PerlLIO_close(sockets[1]);
- errno = save_errno;
+ RESTORE_ERRNO;
return -1;
}
}
@@ -5156,14 +5149,14 @@ Perl_my_socketpair (int family, int type, int protocol, int fd[2]) {
#endif
tidy_up_and_fail:
{
- const int save_errno = errno;
+ dSAVE_ERRNO;
if (listener != -1)
PerlLIO_close(listener);
if (connector != -1)
PerlLIO_close(connector);
if (acceptor != -1)
PerlLIO_close(acceptor);
- errno = save_errno;
+ RESTORE_ERRNO;
return -1;
}
}
diff --git a/vms/vms.c b/vms/vms.c
index c66279d56d..118bc5c120 100644
--- a/vms/vms.c
+++ b/vms/vms.c
@@ -11933,10 +11933,10 @@ Perl_flex_stat_int(pTHX_ const char *fspec, Stat_t *statbufp, int lstat_flag)
char temp_fspec[VMS_MAXRSS];
char *save_spec;
int retval = -1;
- int saved_errno, saved_vaxc_errno;
+ dSAVEDERRNO;
if (!fspec) return retval;
- saved_errno = errno; saved_vaxc_errno = vaxc$errno;
+ SAVE_ERRNO;
strcpy(temp_fspec, fspec);
if (decc_bug_devnull != 0) {
@@ -12063,7 +12063,7 @@ Perl_flex_stat_int(pTHX_ const char *fspec, Stat_t *statbufp, int lstat_flag)
# endif
}
/* If we were successful, leave errno where we found it */
- if (retval == 0) { errno = saved_errno; vaxc$errno = saved_vaxc_errno; }
+ if (retval == 0) RESTORE_ERRNO;
return retval;
} /* end of flex_stat_int() */