Solved

fullstat example!

Posted on 1998-08-21
9
212 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
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 how to use strings and some functions related to them in the C programming language.

776 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