Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

utime undef, undef, @files #712

Closed
p5pRT opened this issue Oct 13, 1999 · 6 comments
Closed

utime undef, undef, @files #712

p5pRT opened this issue Oct 13, 1999 · 6 comments

Comments

@p5pRT
Copy link

p5pRT commented Oct 13, 1999

Migrated from rt.perl.org#1614 (status was 'resolved')

Searchable as RT1614$

@p5pRT
Copy link
Author

p5pRT commented Oct 13, 1999

From andrew@pimlott.ne.mediaone.net

On Solaris, and presumably most systems, the utime(2) system call applies
more lenient authorization checks if I only want to set the time to now (by
passing a NULL struct utimbuf). But the perl utime function always uses the
form that requires me to own the file. I suggest that if the first two
arguments to utime are both undef, perl call the NULL form of utime(2).

Andrew

Perl Info


Site configuration information for perl 5.00503:

Configured by torin at Wed Sep 22 00:18:38 PDT 1999.

Summary of my perl5 (5.0 patchlevel 5 subversion 3) configuration:
  Platform:
    osname=linux, osvers=2.0.36, archname=i386-linux
    uname='linux perv 2.0.36 #2 wed nov 18 03:00:48 pst 1998 i686 unknown '
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=undef useperlio=undef d_sfio=undef
  Compiler:
    cc='cc', optimize='-O2', gccversion=2.95.1 19990809 (prerelease)
    cppflags='-Dbool=char -DHAS_BOOL -D_REENTRANT -DDEBIAN -I/usr/local/include'
    ccflags ='-Dbool=char -DHAS_BOOL -D_REENTRANT -DDEBIAN -I/usr/local/include'
    stdchar='char', d_stdstdio=undef, usevfork=false
    intsize=4, longsize=4, ptrsize=4, doublesize=8
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
    alignbytes=4, usemymalloc=n, prototype=define
  Linker and Libraries:
    ld='cc', ldflags =' -L/usr/local/lib'
    libpth=/usr/local/lib /lib /usr/lib
    libs=-lnsl -lndbm -lgdbm -ldbm -ldb -ldl -lm -lc -lposix -lcrypt
    libc=, so=so, useshrplib=false, libperl=libperl.a
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic'
    cccdlflags='-fPIC', lddlflags='-shared -L/usr/local/lib'

Locally applied patches:
    


@INC for perl 5.00503:
    /usr/lib/perl5/5.005/i386-linux
    /usr/lib/perl5/5.005
    /usr/local/lib/site_perl/i386-linux
    /usr/local/lib/site_perl
    /usr/lib/perl5
    .


Environment for perl 5.00503:
    HOME=/home/andrew
    LANG (unset)
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/home/andrew/bin:/usr/sbin:/sbin:/home/andrew/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/games
    PERL_BADLANG (unset)
    SHELL=/usr/bin/zsh

@p5pRT
Copy link
Author

p5pRT commented May 26, 2001

From @rspier

I've implemented this, cause it sounds like a good idea. (There are
lots of other places where Perl defers to the underlying C library.
This is a good place to do it.) This should not break any existing
functionality.

Patch below.

The documentation for 'utime(2)' on all the systems I could get my
hands on says that this is valid. One, even says this in a section
labeled "STANDARDS".

-R

Inline Patch
--- doio.c.org  Sat May 26 18:37:55 2001
+++ doio.c      Sat May 26 19:00:48 2001
@@ -1667,20 +1667,31 @@
            } utbuf;
 #endif
 
+           SV* accessed = *++mark;
+           SV* modified = *++mark;
+           void * utbufp = &utbuf;
+
+           /* be like C, and if both times are undefined, let the C
+              library figure out what to do.  This usually means
+              "current time" */
+
+           if ( accessed == &PL_sv_undef && modified == &PL_sv_undef )
+             utbufp = NULL;
+           
            Zero(&utbuf, sizeof utbuf, char);
 #ifdef BIG_TIME
-           utbuf.actime = (Time_t)SvNVx(*++mark);      /* time accessed */
-           utbuf.modtime = (Time_t)SvNVx(*++mark);     /* time modified */
+           utbuf.actime = (Time_t)SvNVx(accessed);     /* time accessed */
+           utbuf.modtime = (Time_t)SvNVx(modified);    /* time modified */
 #else
-           utbuf.actime = (Time_t)SvIVx(*++mark);      /* time accessed */
-           utbuf.modtime = (Time_t)SvIVx(*++mark);     /* time modified */
+           utbuf.actime = (Time_t)SvIVx(accessed);     /* time accessed */
+           utbuf.modtime = (Time_t)SvIVx(modified);    /* time modified */
 #endif
            APPLY_TAINT_PROPER();
            tot = sp - mark;
            while (++mark <= sp) {
                char *name = SvPVx(*mark, n_a);
                APPLY_TAINT_PROPER();
-               if (PerlLIO_utime(name, &utbuf))
+               if (PerlLIO_utime(name, utbufp))
                    tot--;
            }
        }
--- pod/perlfunc.pod.original   Sat May 26 10:17:09 2001
+++ pod/perlfunc.pod    Sat May 26 19:39:33 2001
@@ -5622,6 +5622,13 @@
     $now = time;
     utime $now, $now, @ARGV;
 
+If the fisrt two two elements of the list are C<undef>, then the
+system (C Library) utime will be called with a null second argument.
+On most machines, this will set the files access and modification time
+to the current time.  (i.e. equivalent to the example above.)
+
+    utime undef, undef, @ARGV;
+
 =item values HASH
 
 Returns a list consisting of all the values of the named hash.  (In a

@p5pRT
Copy link
Author

p5pRT commented May 26, 2001

From [Unknown Contact. See original ticket]

Thanks! Can I suggest​:

+If the fisrt two two elements of the list are C<undef>, then the
+system (C Library) utime will be called with a null second argument.
+On most machines, this will set the files access and modification time
+to the current time. (i.e. equivalent to the example above.)

Replace "On most ..." with something like

  This will set the file's access and modification time to the
  current time (i.e. equivalent to the example above), but (on
  most systems) will work on any file you can write to, not just
  files you own.

I think if some system were found to do something else with a null
argument, this should be worked around in perl.

(Even if you don't take my suggestion, take my apostrophe, O
illustrious porter. Also, s/fisrt/first/, s/two two/two/.)

Andrew

@p5pRT
Copy link
Author

p5pRT commented May 26, 2001

From @rspier

Thanks! Can I suggest​:

+If the fisrt two two elements of the list are C<undef>, then the
+system (C Library) utime will be called with a null second argument.
+On most machines, this will set the files access and modification time
+to the current time. (i.e. equivalent to the example above.)

Replace "On most ..." with something like

This will set the file's access and modification time to the
current time (i.e. equivalent to the example above), but (on
most systems) will work on any file you can write to, not just
files you own.

The ownership rules vary from system to system, but are generaly the
same for both cases. (i.e providing arguments/not providing
arguments) Because that is dependent on the actual underlying
implementation, I don't think the perl documentation should mention
that.

I think if some system were found to do something else with a null
argument, this should be worked around in perl.

(Even if you don't take my suggestion, take my apostrophe, O
illustrious porter. Also, s/fisrt/first/, s/two two/two/.)

Andrew

New doc patch follows​:

-R

Inline Patch
--- perlfunc.pod.original       Sat May 26 10:17:09 2001
+++ perlfunc.pod        Sun May 27 00:16:59 2001
@@ -5622,6 +5622,13 @@
     $now = time;
     utime $now, $now, @ARGV;
 
+If the first two elements of the list are C<undef>, then the utime(2)
+function in the C library will be called with a null second argument.
+On most systems, this will set the file's access and modification
+times to the current time.  (i.e. equivalent to the example above.)
+
+    utime undef, undef, @ARGV;
+
 =item values HASH
 
 Returns a list consisting of all the values of the named hash.  (In a

@p5pRT
Copy link
Author

p5pRT commented May 27, 2001

From @rspier

I thought about that, and it was starting to look real ugly. the
t/io/fs.t tests for utime are a small nest of platform varying tests,
and I really didn't want to touch or expand them.

The patch shouldn't change the common case functionality.

-R

@p5pRT
Copy link
Author

p5pRT commented May 27, 2001

From @jhi

I believe "rat's nest" is the technical term :-)

and I really didn't want to touch or expand them.

The patch shouldn't change the common case functionality.

True. I'm just afraid that in some far-away platform utime(2) will
crash and burn with NULL arguments...

-R

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant