Solved

fullstat example!

Posted on 1998-08-21
9
194 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
 

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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

706 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now