Solved

fullstat example!

Posted on 1998-08-21
9
218 Views
Last Modified: 2010-04-15
i need know information about a file, but return -1

fullstat("/ivan/asc.c",FL_NOFOLLOW,buffer)

can you give a correct example?
aix or unix
0
Comment
Question by:navi_ivan
  • 4
  • 2
  • 2
  • +1
9 Comments
 
LVL 11

Expert Comment

by:alexo
ID: 1252245
Ivan, "/ivan/asc.c" means file asc.c residing in directory ivan directly under the root.  Are you sure it is the case?  In most multiuser settings you'd use something like "~ivan/asc.c" meaning file asc.c in the home directory of user ivan.

Anyway, you can check the errno variable for the probable cause of the error.
0
 
LVL 1

Expert Comment

by:Staplehead
ID: 1252246
ivan,

incidentally, -1 probably IS a correct return code...

try "ls /ivan/asc.c".  if the file doesn't exist, then -1 is a valid return code.

in your code, you could do something like:

if (fullstat("/ivan/asc.c",FL_NOFOLLOW,buffer)  == -1) {
    perror("/ivan/asc.c");
}

also, i'm assuming the FL_NOFOLLOW parm says not to follow symbolic links, so if asc.c is a symlink to another file, then your return code refers to it, not anything that it might point to...

larry
0
 
LVL 3

Expert Comment

by:braveheart
ID: 1252247
My man pages confirm that fullstat returns -1 when it encounters an error, so follow staplehead's suggestions.

Incidentally, my man pages say that fullstat is obsolete and you should probably be using stat or statx.
0
Portable, direct connect server access

The ATEN CV211 connects a laptop directly to any server allowing you instant access to perform data maintenance and local operations, for quick troubleshooting, updating, service and repair.

 

Author Comment

by:navi_ivan
ID: 1252248
thanks but...
this think do not work.

perror return :
bad addres
and ls command return that it exitst.

i will try whith braveheart suggestion.

thanks any way.
0
 
LVL 1

Expert Comment

by:Staplehead
ID: 1252249
ivan,

here's what my man pages say about the "bad address" error (i.e., try "man errno"):

      [EFAULT]       Bad address.  The system encountered a hardware fault
                     in attempting to use an argument of a system call; can
                     also result from passing the wrong number of parameters
                     to a system call.  The reliable detection of this error
                     is implementation dependent.

so, using braveheart's suggestion, try this:

#include <sys/types.h>
#include <sys/stat.h>

int main () {
    struct stat buf;

    if (stat ("/ivan/asc.c", &buf) == -1) {
        perror ("/ivan/asc.c");
    }
}


larry
0
 
LVL 3

Expert Comment

by:braveheart
ID: 1252250
This is the EFAULT error code, described in the man pages to  intro(2). The system encountered a hardware fault in attempting to use an argument of a routine. For example, errno potentially may be set to EFAULT any time a routine that takes a pointer argument is passed an invalid address.

Maybe the fault is not with the filename but with the way you have declared or are passing buffer.
0
 
LVL 3

Expert Comment

by:braveheart
ID: 1252251
Oops! Great minds think alike. It seems that Staplehead's answer got here before mine had left the screen.
0
 

Author Comment

by:navi_ivan
ID: 1252252
ok. it working, but how can print the result (stucture)?
gracias.
0
 
LVL 3

Accepted Solution

by:
braveheart earned 10 total points
ID: 1252253
Unless you can find a special function to print out the structure (which is unlikely) you will have to write one yourself:


printf("File mode is %d\n",buf.st_mode);
printf("Inode number is %d\n",buf.st_ino);
      .
      .
      .
printf("No. of blocks is %d\n",buf.st_blocks);

See "man stat" and the include files /usr/include/sys/types.h and /usr/include/sys/stat.h for information about the types of the structure members and the structure itself.
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question