@@ -1191,6 +1191,30 @@ Perl_nextargv(pTHX_ GV *gv, bool nomagicopen)
1191
1191
return NULL ;
1192
1192
}
1193
1193
1194
+ #ifdef ARGV_USE_ATFUNCTIONS
1195
+ # if defined(__FreeBSD__ )
1196
+
1197
+ /* FreeBSD 11 renameat() mis-behaves strangely with absolute paths in cases where the
1198
+ * equivalent rename() succeeds
1199
+ */
1200
+ static int
1201
+ S_my_renameat (int olddfd , const char * oldpath , int newdfd , const char * newpath ) {
1202
+ /* this is intended only for use in Perl_do_close() */
1203
+ assert (olddfd == newdfd );
1204
+ assert (PERL_FILE_IS_ABSOLUTE (oldpath ) == PERL_FILE_IS_ABSOLUTE (newpath ));
1205
+ if (PERL_FILE_IS_ABSOLUTE (oldpath )) {
1206
+ return PerlLIO_rename (oldpath , newpath );
1207
+ }
1208
+ else {
1209
+ return renameat (olddfd , oldpath , newdfd , newpath );
1210
+ }
1211
+ }
1212
+
1213
+ # else
1214
+ # define S_my_renameat (dh1 , pv1 , dh2 , pv2 ) renameat((dh1), (pv1), (dh2), (pv2))
1215
+ # endif /* if defined(__FreeBSD__) */
1216
+ #endif
1217
+
1194
1218
/* explicit renamed to avoid C++ conflict -- kja */
1195
1219
bool
1196
1220
Perl_do_close (pTHX_ GV * gv , bool not_implicit )
@@ -1320,7 +1344,7 @@ Perl_do_close(pTHX_ GV *gv, bool not_implicit)
1320
1344
#ifdef HAS_RENAME
1321
1345
if (
1322
1346
# ifdef ARGV_USE_ATFUNCTIONS
1323
- renameat (dfd , orig_pv , dfd , SvPVX (* back_psv )) < 0
1347
+ S_my_renameat (dfd , orig_pv , dfd , SvPVX (* back_psv )) < 0
1324
1348
# else
1325
1349
PerlLIO_rename (orig_pv , SvPVX (* back_psv )) < 0
1326
1350
# endif
@@ -1360,7 +1384,7 @@ Perl_do_close(pTHX_ GV *gv, bool not_implicit)
1360
1384
if (
1361
1385
#ifdef HAS_RENAME
1362
1386
# ifdef ARGV_USE_ATFUNCTIONS
1363
- renameat (dfd , SvPVX (* temp_psv ), dfd , orig_pv ) < 0
1387
+ S_my_renameat (dfd , SvPVX (* temp_psv ), dfd , orig_pv ) < 0
1364
1388
# else
1365
1389
PerlLIO_rename (SvPVX (* temp_psv ), orig_pv ) < 0
1366
1390
# endif
0 commit comments