Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

fullstat example!

Posted on 1998-08-21
9
Medium Priority
?
240 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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 30 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
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.
Suggested Courses

618 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