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

  • SEARCH
  • Home
  • 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 8356831
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T10:17:56+00:00 2026-06-09T10:17:56+00:00

When my program tries to stat() a file containing specific UTF-8 characters, the stat()

  • 0

When my program tries to stat() a file containing specific UTF-8 characters, the stat() function returns an error. For example, I can open the file /tmp/surgateDlpMgQure/Özkul Gazete with vi, but passing this same file to stat() generates an error. System locale settings are:

LANG=en_US.UTF-8

LC_CTYPE="en_US.UTF-8"

LC_COLLATE=C

LC_TIME="en_US.UTF-8"

LC_NUMERIC="en_US.UTF-8"

LC_MONETARY="en_US.UTF-8"

LC_MESSAGES="en_US.UTF-8"

LC_ALL=

Should I do something in order for stat() to understand the UTF-8 characters?

Here is the code:

int main ()
{
    struct stat s;
    if (stat("/tmp/surgateDlpMgQure/Özkul Gazete", &s) == -1)
            perror("stat");


    switch (s.st_mode & S_IFMT) {
            case S_IFBLK:  printf("block device\n");            break;
            case S_IFCHR:  printf("character device\n");        break;
            case S_IFDIR:  printf("directory\n");               break;
            case S_IFIFO:  printf("FIFO/pipe\n");               break;
            case S_IFLNK:  printf("symlink\n");                 break;
            case S_IFREG:  printf("regular file\n");            break;
            case S_IFSOCK: printf("socket\n");                  break;
            default:       printf("unknown?\n");                break;
    }

 return 0;
}
  • 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-06-09T10:17:57+00:00Added an answer on June 9, 2026 at 10:17 am

    The problem is probably that the encoding of the file name isn’t the
    same as the encoding you’re using internally in your program. The key
    questions here are who created the file (and gave it this name), and
    where the string in your code comes from. Most of Unix is agnostic with
    regards to the encoding, as long as a few special characters, like
    '/', have the expected encoding. Thus, independently of your
    current locale
    , a file name can be in Latin-1, Latin-5 (just guessing,
    but the name looks Turkish) or UTF-8. Practically nothing in Unix cares,
    but you have to ensure that in your program, you use the same encoding
    as was used to create the file, or the names won’t match. (In practice,
    I’ve found the simplest policy to be to limit the characters in a
    filename to a very small set: the ASCII alphanumeric characters, digits,
    '_' and possibly '-'.)

    If you’re not sure about the actual encoding of the filename on disk,
    you can use ls | od -t x1 -tc to find out the actual value of the
    bytes in it. If your Ö is 0xD6, then the encoding is either Latin-1
    or Latin-5 (and it probably won’t make much difference which), and
    you’ll have to ensure that the filename you pass stat (or open, or
    any other functions which take a filename) is encoded in one of these
    encodings. If instead you have the two byte sequence 0xC3, 0x96, then
    the filename is UTF-8.

    If you do want to support characters outside of the ASCII subset, then
    I’d strongly recommend that you ensure that all filenames are encoded
    in UTF-8. Supposing that you can—the encoding will be decided by
    the program creating the file, and if it’s not your program (or if
    you’re receiving the file from another system), you may not be able to
    do anything about it. In the worst case scenario, you may even have to
    use opendir and readdir with some sort of matching algorithm to find
    the actual filename (in whatever the encoding), and use it.

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

Sidebar

Related Questions

If a program tries to use my file-reading class to access part of a
I'm encountering a hang when the program tries to access the fruit database. I've
I have a program that tries to shrink a double down to a desired
Here is a C# program that tries Marshal.SizeOf on a few different types: using
I have written an ActionScript client program that tries to connect to a local
In my program, if a user tries to leave a page, he'll receive a
Well, I have this program, the download option is working fine. I can access
I am referring the following article learning symbolic link attacks: struct stat st; FILE
I have some trouble regarding my lab assignment: When my program tries to prompt
I'm working on an app that needs to intercept when a program tries to

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.