473,769 Members | 6,926 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

stat() does not work for me on Cygwin/Windows

32 New Member
Does anyone know about this problem? I tried using the "old" _stat for Cygwin/Windows but that doesn't help.

The problem I am having is st_size is ALWAYS 16777216 for any file I am stat'ing and that value is incorrect anyway. Here is an example of the code:

Expand|Select|Wrap|Line Numbers
  1. char *filename = "C:\\Program Files\\Somedir\\medfile.txt";
  2. int ret;
  3.  
  4. #if OS == LINUX
  5.     struct  stat sbuf;
  6.     ret = stat( filename, &sbuf );
  7. #elif OS == CYGWIN
  8.     struct _stat sbuf;
  9.     ret = _stat( filename, &sbuf );
  10. #endif
  11.  
  12. printf("ret : %d, sbuf.st_size: %dl \n\n", ret, sbuf.st_size);
  13.  
result is :

0, 16777216


btw - using the FILE functions, I get the correct sizes; e.g.
Expand|Select|Wrap|Line Numbers
  1. sizeFile = (UINT32)ftell( fp );
  2.  
but I don't want to open and close the file just to get the size.

helpppp
Aug 11 '10 #1
4 4414
weaknessforcats
9,208 Recognized Expert Moderator Expert
Your file should be:

Expand|Select|Wrap|Line Numbers
  1. char *filename = "C:\\Program\\Files\\Somedir\\medfile.txt";
I would just opne the file and do a seek to the end followed by a tell. That will give you the number of bytes in the file.
Aug 11 '10 #2
dissectcode2
32 New Member
There is a \\ between Program and Files? I tried the \\ in every other spot, and it is the same error (actually that is how I have it in my code, correctly)
Aug 11 '10 #3
weaknessforcats
9,208 Recognized Expert Moderator Expert
There is no \\ between Program and files. It's a typo.
Aug 11 '10 #4
BillyTKid
7 New Member
try %ld in printf, not %dl
Aug 12 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

4
1847
by: Hal Halloway | last post by:
can mysql work in Windows but not Solaris? Is there any reason you can see why the fulltext php/mysql code below works OK on my win2k php4.3.6. mysql 4.1.3 pc but does *not* work when put on a Solaris Server with php5 mysql 4.1.6 ? That is what happens...I'm suspicious of the accent characters in the code but I am not sure if there's any truth to my suspicion and how I'd even test or fix it(?) Here's the snip I think causes the...
2
5682
by: Peter O'Reilly | last post by:
I am experiencing difficulty access a mapped network drive in an ASP.NET application. While using the .Net framework v 1.1 implementation of System.IO.Directory.Exists(), it fails to recognize a mapped network drive. This is true if the path specified uses a mapped drive letter or is expressed as a UNC address. I have also tried the drive letter and UNC paths with and without trailing backslashes, respectively.
3
2409
by: Pankaj | last post by:
I am facing a very basic problem as any new bie would face. I know perl and now i want to use python In perl, it is very simple , just "perl scriptname.pl" will execute the script. But i think python is worse than perl
0
1699
by: anagai | last post by:
hi I have the java bridge library working fine on a windows 2000 and running apache 1.3 but cannot for whatever reason get it to work on windows xp and apache 2.0.5 Ive included the following in php.ini: java.class.path = "c:\PHP\ext\JavaBridge.jar;"
0
1274
by: anupamak | last post by:
Hello, I am developing an application in VC++.Net and windows xp using the setupapi, which has to work as windows service. Actually, in the beginning, my application was developed in VC++.Net, MFC with GUI. But now i am decoupling the GUI and want to make the application work as windows service. As a part of this, I have created my application using the windows service template. But when i embedded the files such as Dbt.h and my own...
1
2197
by: misiek3d | last post by:
Hello I want to use IronPython as Windows Scripting Host language. Is it possible? How can I do it? I know that ActivePython works as WSH language but for specific reasons I need to use IronPython. regards Michal
4
1712
by: fperri | last post by:
I don't know if its me, but any compilier that I try to use will compile but not create the exe when linking on my computer. Is there a problem with Windows Vista and compiling C code? I have to use C for a course and I can't get anything to run. I know my code is right because I'm just using a sample program to test. #include <stdio.h> main() { printf ("Hello World!\n"); }
0
1516
by: tarunsingh19 | last post by:
Oracle 8i express edition work in windows Xp sp2?
0
1157
by: bamusic | last post by:
I have a perl script for unix which uses a socket to read data from gsm modem connected to com port.I need to convert it to windows.I think most of the script is going to be same except the line which establishes the socket connection. Could someone please help me to know which lines I should change so that it will work on windows. Here is the script #!/usr/bin/perl -w # TRG: Perl script to exercise GSM card through a set of diagnostic...
0
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10214
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9996
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8872
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6674
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5304
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3963
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.