NO

Author Topic: fopen problem, will not open file where name length bigger than than 31  (Read 12939 times)

raviv

  • Guest
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

  • Guest
Re: fopen problem, will not open file where name length bigger than than 31
« Reply #1 on: February 16, 2011, 06:36:57 PM »
C:\Render\Floors\1234567890a.bmp

should be

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

John

raviv

  • Guest
I work in win32 env
anyway I tried,

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

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

...

CommonTater

  • Guest
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

  • Guest
Bingo,

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

Thank you

CommonTater

  • Guest
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.


Offline Stefan Pendl

  • Global Moderator
  • Member
  • *****
  • Posts: 582
    • Homepage
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

  • Guest
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.


Offline Stefan Pendl

  • Global Moderator
  • Member
  • *****
  • Posts: 582
    • Homepage
From the CreateFile Function description at MSDN:

Quote
In 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

  • Guest
From the CreateFile Function description at MSDN:

Quote
In 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.