fopen problem, will not open file where name length bigger than than 31

Started by raviv, February 16, 2011, 04:53:44 PM

Previous topic - Next topic

raviv

Problem example:

fopen() succesfully opens:
C:\Render\Floors\1234567890.bmp

But fails to open:
C:\Render\Floors\1234567890a.bmp

what could be the problem?

Thank you

JohnF

C:\Render\Floors\1234567890a.bmp

should be

C:\\Render\\Floors\\1234567890a.bmp

John

raviv

I work in win32 env
anyway I tried,

1.   C:\\Render\\Floors\\1234567890.bmp    => FAILED

2.   C:\Render\Floors\1234567890.bmp        => SUCCESS

...

CommonTater

How big is the buffer you are storing your file name in?  

Unless the filename is "hard coded', I typically allow 256 characters (MAX_PATH in windows) but I'm guessing you have it set to 32... which is far too small.



raviv

Bingo,

here is your guess(and my mistake):
#define MAXFLDSIZE 32

Thank you

CommonTater

Quote from: raviv on March 02, 2011, 12:21:43 PM
Bingo,

here is your guess(and my mistake):
#define MAXFLDSIZE 32

Thank you

;D  Every once in a while I get real lucky...

If you are using #include <windows.h> you can use their MAX_PATH as I mentioned.  It's used throughout windows so you can be pretty sure you won't get a filename longer than that.


Stefan Pendl

The ANSI Windows API functions use MAX_PATH as the maximum path length.

The UNICODE functions use 32kB as the maximum path length.

You just need to decide, which route to go.
---
Stefan

Proud member of the UltraDefrag Development Team

CommonTater

Quote from: Stefan Pendl on March 02, 2011, 11:07:39 PM
The ANSI Windows API functions use MAX_PATH as the maximum path length.

The UNICODE functions use 32kB as the maximum path length.

You just need to decide, which route to go.

I may be horridly mistaken here but I don't think that's universal... MAX_PATH is used internally by most windows functions...  It's still 260 characters but of course in Unicode a character is 16 bits, not 8.


Stefan Pendl

From the CreateFile Function description at MSDN:

QuoteIn the ANSI version of this function, the name is limited to MAX_PATH characters. To extend this limit to 32,767 wide characters, call the Unicode version of the function and prepend "\\?\" to the path.

And this is not the only location, where you can find it.
---
Stefan

Proud member of the UltraDefrag Development Team

CommonTater

Quote from: Stefan Pendl on March 02, 2011, 11:54:57 PM
From the CreateFile Function description at MSDN:

QuoteIn the ANSI version of this function, the name is limited to MAX_PATH characters. To extend this limit to 32,767 wide characters, call the Unicode version of the function and prepend "\\?\" to the path.

And this is not the only location, where you can find it.

Yes, but only with the special code... without that: MAX_PATH, either way.  This much I already knew.