Questions tagged [fstat]

38 questions
41
votes
3 answers

Difference between lstat fstat and stat in C

Im writing a school assignment in C to search through a file system for directories, regular files and symlinks. For now i use lstat to get information about items. So whats the difference between lstat fstat and stat system calls?
uzr
  • 1,210
  • 1
  • 13
  • 26
14
votes
6 answers

Check if a fstream is either a file or directory

I'm using C++ fstream to read a config file. #include std::ifstream my_file(my_filename); Right now, if I pass the path of a directory, it silently ignores this. E.g. my_file.good() returns true, even if my_filename is a directory. Since…
MacFreek
  • 3,207
  • 2
  • 31
  • 41
10
votes
5 answers

What are the advantages of using fstat() vs stat()?

If I have an open file with a known file descriptor, what are the advantages of using fstat(), versus stat()? Why isn't there only one function? int fstat(int fildes, struct stat *buf) int stat(const char *path, struct stat *buf)
Rasteril
  • 605
  • 1
  • 5
  • 16
8
votes
2 answers

Using stat() after fopen() to Avoid TOCTOU Problems?

Title says it all: can one use stat() after fopen() to avoid Time of Check to Time of Use (TOCTOU) race conditions? Some details: I am writing a C program that only reads files, but needs to error properly when asked to read a directory. As of right…
Gavin D. Howard
  • 371
  • 4
  • 9
8
votes
1 answer

stat(), fstat(), lstat(), and fopen(); how to write TOCTOU protected system independent code

I've been dealing with a problem for a few weeks now updating 20 year code that needs to be system independent (work on both Linux and Windows). It involves Time-of-Check, Time-of-Use (TOCTOU) issues. I made a thread here, but it didn't go very…
user3633538
5
votes
1 answer

Get file's owner and group using boost

I want to get the owner and group from a file using boost::filesystem, but never found any way to do so. I can get the file's permissions, but as I don't know the file's owner this just doesn't mean anything. I found the posix fstat function, but…
Jaffa
  • 12,442
  • 4
  • 49
  • 101
3
votes
2 answers

How to discern, if a directory is NFS-mounted from Ansible?

I need to set up an application directory for a "hairy" app. Depending on the case, the directory may be local to each server participating, or shared among several servers via NFS. So, I need to be able to detect, whether the given path is local or…
Mikhail T.
  • 3,043
  • 3
  • 29
  • 46
3
votes
1 answer

fstat Returning 0 File Size

I thought I understood fstat, I was wrong. I need to know the size of the file then read from the file. fileN Has the path of the file and the name of the file. It looks like this. 0.txt struct stat fileStat; FILE *fp; int fd = 0; int i; for(i…
Mike John
  • 818
  • 4
  • 11
  • 29
3
votes
1 answer

Linux Descriptor Type

How do I get the descriptor type? I am using epoll to monitor lots of descriptors like sockets, timers, and signals. I saw it is possible using fstat, but the mode only says something about sockets and pipes. fstat manpage. Is there a special…
Kouros
  • 341
  • 5
  • 19
2
votes
1 answer

Challenging regression to make maybe with a loop and F-stat

I'm working on a panel dataset with thousands of observations. Let me simplify things as much as I can. Suppose I have the following dataset set.seed(123) gdp_usa=runif(16,8,9) gdp_bel=c(9.22707, 9.245133, 9.272205, 9.31063, 9.339993, …
Maximilian
  • 235
  • 1
  • 7
2
votes
0 answers

Undefined symbol: fstat in dynamic library

I'm writing a dynamic library that's loaded at runtime as a plugin. At runtime, the library fails to load with the following message: dlerror:/path/to/so: undefined symbol: fstat The dynamic library consists of a bunch of static libraries linked…
leecbaker
  • 3,611
  • 2
  • 35
  • 51
2
votes
2 answers

statsmodels patsy hypothesis testing categorical variable in constraint 'C()'

Hi am running the following model with statsmodel and it works fine. from statsmodels.formula.api import ols from statsmodels.iolib.summary2 import summary_col #for summary stats of large tables time_FE_str = ' + C(hour_of_day) + C(day_of_week) +…
Niko
  • 101
  • 2
  • 11
2
votes
1 answer

fstat behavior after a read

In many cases I have seen an fstat call performed directly after the file descriptor has been assigned from a call to open: fd = open(file, flags, mode); fstat_result = fstat(fd, &stat_log); Does fstat behave any differently if one has already…
dtmland
  • 2,136
  • 4
  • 22
  • 45
2
votes
1 answer

any reason to call fsync before a call to fstat

I have a piece of legacy code that issues a call to fsync before a call to fstat to determine the filesize of the target file. (specifically the code is only accessing st_size out of the stat struct.) Having looked at the docs, I don't believe this…
Pablitorun
  • 1,035
  • 1
  • 8
  • 18
2
votes
1 answer

fstat() st_nlink=1 even after linking more files

#include #include #include #include int main(int argc, char const *argv[]) { struct stat buf; int fd; if (fd = open(argv[1], O_RDWR | O_CREAT)<0) { printf("file open…
Abdul
  • 231
  • 3
  • 14
1
2 3