Solved

fullstat example!

Posted on 1998-08-21
9
205 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
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
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

ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Estimate porting issues. 9 118
Which version of C should I use when Perl is too slow? 13 173
How do I install gcc 4.8.4 on a Linux Ubuntu 14.04 machine? 5 1,567
C hashtable library 3 82
Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
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…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.

910 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