Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3844386
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T16:04:53+00:00 2026-05-19T16:04:53+00:00

When calling access(2) and getting an errno == ENOENT the man page says: ENOENT

  • 0

When calling access(2) and getting an errno == ENOENT the man page says:

   ENOENT A directory component in pathname would have been accessible but
          does not exist or was a dangling symbolic link.

However, in my case I was trying to create a file in /tmp/ and the directory component was accessible and exists. Could it be that ENOENT is also given when the file system has too many files in a directory? In my case, /tmp/ had grown to an enormous number of small temporary files. Can I eventually reach a limit and get this ENOENT? If so, how can I programmatically differentiate this case?

— More stripped down code added and more explaination —

Looking closer, it appears that the file exists on disk, although if that is case, why would mkstemp() give me a collision? I doubt I could I have exhausted the XXXXXX space, 36^6 = 2.1 billion!

char *fileName = new char[256];

strncpy(fileName, "/tmp/somePathXXXXXX", 255);

int fileDescriptor = mkstemp(fileName);

if (fileDescriptor == -1) {
  struct stat statusFileInfo;
  int result = stat(fileName, &statusFileInfo);

  if (result == 0) {
    mode_t mode = statusFileInfo.st_mode;

    if (S_ISREG(mode)) {
      // Check permission.
      int result = access(fileName, W_OK);

      if (result) {
        // Code landed here with errno == ENOENT.
        ...
      }
    }
  }
}

Please note my application’s code has worked fine for thousands of invocations, then I saw this one failure. The code above is a simplified synthesis down to the key ingredients of the failure condition.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T16:04:53+00:00Added an answer on May 19, 2026 at 4:04 pm

    The main meaning of ENOENT is ‘no such file or directory’. It means that the name you tried to access() was not there.

    If you were trying to create the file, then maybe, perhaps, you would get ENOENT when there are ‘too many files in a directory’, but you’d be more likely to get some other error, I think – perhaps ENOSPC (no space left on the device) if there was a problem with your inode table overflowing.


    The code that appeared since I wrote the first part of the answer needs correcting.

    char *fileName = "/tmp/somePathXXXXXX";
    int fileDescriptor = mkstemp(fileName);
    

    You are lucky – or maybe unlucky – that this did not cause a segmentation fault. That is categorically not the correct way to call mkstemp() or any of the related functions. You must pass a modifiable string, and that is a string constant, and hence not modifiable. It might well be stored in read-only memory. It seems that you got away with it – but on the second invocation, you are passing a string that does not have 6 X’s in it (because mkstemp() wrote over the X’s the first time). So, it is no wonder that the file already exists.

    If you’re going to play like that, you must use something equivalent to:

    const char refFileName[] = "/tmp/somePathXXXXXX";
    char fileName[32];
    strcpy(fileName, refFileName);
    int fd = mkstemp(fileName);
    

    Now the mkstemp() function has modifiable text to work with.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm getting a 401 (access denied) calling a method on an internal web service.
I am getting this error while calling $.ajax methods Error: [Exception... Access to restricted
I have a flex 4.6 application calling a web service that access a MS
I have an issue where I'm getting bad access exceptions but only when running
Calling getActionBar returns null . This has been frequently reported so I've made sure
I have a rather complicated toolchain so prepare for a lengthy post until getting
I have two projects, both of them data access layers, and both using EF.
I've been staring at this for a while and not getting very far. FruitBasketFactory,
I have got an application, that is getting data via XML-files. During the parsing-part
I am getting an httpwebresponse stream (of a flash file), and I would like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.