how to print st_mtim; how to use stat() in a user given dir printout

how to print st_mtim; how to use stat() in a user given dir printout

Post by jada » Tue, 04 Nov 1997 04:00:00



Hello all,

I have two basic problems that I am hoping someone could help me with.
I am writing a version of the ls program and I need to know:

1) I am having a problem getting the stat structure to get the status of
files from a directory that the user inputs as an argument.
EXAMPLE: --this is pseudocode, I didn't check for exavt syntax --
                  dirp = opendir(argv[1]) /* open directory */
                   while(dp = readdir(dirp){
                            strat(dp->d_name,&st)
                            /* here is the problem, the stat function
looks in the current directory for the file dp->d_name.  How do I make a
path out of the user entered directory and the file name located in the
dp structure?  I tried using strcat and strcopy but those only crashed
the program. */

2)  How do I print out the mtime.
   EXAMPLE:
                      printf("%[what do I place here?], sp->st_mtim);

Any hepl would be greatly appreciated.  If I could get a response via
email that would be great.

Sherman

 
 
 

how to print st_mtim; how to use stat() in a user given dir printout

Post by Boyd Rober » Wed, 05 Nov 1997 04:00:00



Quote:

>By far the easiest way to handle this is to chdir() to the directory
>that you are reading.

I hate programs that chdir on you.

--

En fin, bon, bref, si tu veux, point la ligne, voil quoi -- Jacques



 
 
 

how to print st_mtim; how to use stat() in a user given dir printout

Post by Andrew Giert » Wed, 05 Nov 1997 04:00:00


 >> By far the easiest way to handle this is to chdir() to the directory
 >> that you are reading.

 Boyd> I hate programs that chdir on you.

How often do you notice?

FreeBSD's ls does, as do most directory reading programs on FreeBSD
(they generally use the fts library, which defaults to changing
directories unless you use FTS_NOCHDIR or FTS_LOGICAL).

--
Andrew.

comp.unix.programmer FAQ: see <URL: http://www.erlenstar.demon.co.uk/unix/>
                           or <URL: http://www.whitefang.com/unix/>

 
 
 

how to print st_mtim; how to use stat() in a user given dir printout

Post by Andrew Giert » Wed, 05 Nov 1997 04:00:00


 jadai> Hello all,
 jadai> I have two basic problems that I am hoping someone could help
 jadai> me with.  I am writing a version of the ls program and I need
 jadai> to know:

 jadai> 1) I am having a problem getting the stat structure to get the
 jadai> status of files from a directory that the user inputs as an
 jadai> argument.
 [...]
 jadai> /* here is the problem, the stat function looks in the current
 jadai> directory for the file dp->d_name.  How do I make a path out
 jadai> of the user entered directory and the file name located in the
 jadai> dp structure?  I tried using strcat and strcopy but those only
 jadai> crashed the program. */

By far the easiest way to handle this is to chdir() to the directory
that you are reading. This not only simplifies constructing the
pathnames, but also makes the stat() calls slightly faster (since less
work is being done in the pathname lookup).

Alternatively, construct a path from the user-supplied name and the name
read from the directory. It sounds like you've tried this but done the
string manipulations incorrectly.

 jadai> 2)  How do I print out the mtime.
 jadai>    EXAMPLE:
 jadai>                   printf("%[what do I place here?], sp->st_mtim);

Look up the functions ctime, localtime, strftime.

--
Andrew.

comp.unix.programmer FAQ: see <URL: http://www.erlenstar.demon.co.uk/unix/>
                           or <URL: http://www.whitefang.com/unix/>

 
 
 

how to print st_mtim; how to use stat() in a user given dir printout

Post by James Youngma » Wed, 05 Nov 1997 04:00:00


  >>> By far the easiest way to handle this is to chdir() to the
  >>> directory that you are reading.

  Boyd> I hate programs that chdir on you.

  AG> How often do you notice?

  AG> FreeBSD's ls does, as do most directory reading programs on
  AG> FreeBSD (they generally use the fts library, which defaults to
  AG> changing directories unless you use FTS_NOCHDIR or FTS_LOGICAL).

Do they set the coredump limit to zero first?

 
 
 

1. after changing a user's home dir, cd ~user in ksh still use old dir

See example below:

[julie:/export/home/root]grep oracle7 /etc/passwd
oracle7:x:65535:65535:Oracle Workgroup Server user:/opt:/usr/bin/sh
[julie:/export/home/root]cd ~oracle7            
ksh: /opt/oracle7:  not found

Please note another subshell will do fine:

[julie:/export/home/root]/bin/ksh
[julie:/export/home/root]cd ~oracle7  

What does this mean? Thanks.
--
Michael Wang
http://www.mindspring.com/~mwang

2. CGI specification considered vague

3. Urgent: "lpc stat" and "lpc stat lj02" gives different result

4. Stripe Drives?

5. How do I display current dir if no dir is given

6. AIX 3.2.5 Installation Guide

7. od gives "Is a directory" when used on dir files

8. input & output logging

9. input on giving root access to user dirs?

10. Wrong time from stat.st_atime using stat()

11. using stat from sys/stat.h

12. Creating some identical files/dir's in all users dir's

13. queueing printouts from remote systems to a solaris 2.3 print class...