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 3780472
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T10:49:21+00:00 2026-05-19T10:49:21+00:00

I try to write program where part of it is listing all directories (especially

  • 0

I try to write program where part of it is listing all directories (especially starting from /), but I have a problem with /proc/self which is infinitely recursive (I get /proc/self/task/4300/fd/3/proc/self/task/4300/fd/3/proc/self/task/4300/fd/3/proc/… and so on). What is nice way to deal with it?

EDIT: Program is written in C language and I use opendir(), readdir()

  • 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-19T10:49:21+00:00Added an answer on May 19, 2026 at 10:49 am

    You can use the S_ISLNK macro to test the st_mode field returned by a call to lstat. If the file is a symbolic link, do not try to follow it.

    [user@machine:~]:./list | grep link
    /proc/mounts is a symbolic link
    /proc/self is a symbolic link
    

    Example code

    #include <stdio.h>     // For perror
    #include <stdlib.h>
    #include <sys/types.h> // For stat, opendir, readdir
    #include <sys/stat.h>  // For stat
    #include <unistd.h>    // For stat
    #include <dirent.h>    // For opendir, readdir
    
    const char *prefix = "/proc";
    
    int main(void)
    {
        DIR *dir;
        struct dirent *entry;
        int result;
        struct stat status;
        char path[PATH_MAX];
    
        dir = opendir(prefix);
        if (!dir)
        {
            perror("opendir");
            exit(1);
        }
    
        entry = readdir(dir);
        while (entry)
        {
            result = snprintf(path, sizeof(path), "%s", prefix);
            snprintf(&path[result], sizeof(path) - result, "/%s", entry->d_name);
            printf("%s", path);
    
            result = lstat(path, &status);
            if (-1 == result)
            {
                printf("\n");
                perror("stat");
                exit(2);
            }
    
            if (S_ISLNK(status.st_mode))
            {
                printf("%s", " is a symbolic link");
            }
    
            printf("\n");
    
            entry = readdir(dir);
        }
    
        return(0);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to write a blackjack program, but when I try to send
I try to write a javascript Self-Executing Anonymous Function window.App = window.App || {}
I try to write DSL class Warcraft class << self def config unless @instance
I try to write :ab in Vim for faster coding but the question is
I am trying to write a part of a multithreaded program where each thread
I have a problem with writting this program I need to read a csv
Problem: Write a program that prompts the user to enter some number of 1,
I have a struct defined in my program as: struct memregion { void *from;
in a part of my code i write in socket from server and wait
I have a self-modifying program which writes to the program flash area (it does

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.