S_ISDIR (dirent.h) ?!
  • Order of the Butterfly
    Order of the Butterfly
    beworld
    Posts: 364 from 2010/2/10
    From: FRANCE
    Hi,

    I try a simple code "c" :

    Code:

    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <math.h>
    #include <time.h>
    #include <sys/types.h>
    #include <sys/stat.h>

    #include <proto/dos.h>
    #include <dirent.h>

    int main(int argc, char * argv[])
    {

    struct dirent* entry;
    struct stat buf;


    DIR* current_directory;
    char curdir[FILENAME_MAX];


    sprintf(curdir,"MORPHOS:%s","");


    current_directory = opendir(curdir);

    while ((entry=readdir(current_directory)))
    {

    printf("filename=%s ",entry->d_name);

    stat(entry->d_name, &buf);

    if (S_ISDIR(buf.st_mode)) {
    printf(" is dir n ");

    } else{
    printf("is file n");

    }
    }
    closedir(current_directory);

    return(0);
    }


    Juste list files and directory of my MORPHOS: volume, and check if are directory or file :

    Result.. i dont understand, anyone can help me ?


    Code:
    filename=MorphOS.readme is file
    filename=MorphOS.readme.info is file
    filename=MorphOS is file
    filename=Development is file
    filename=Development.info is file
    filename=Applications.info is file
    filename=disk.info is file
    filename=Data is file
    filename=Classes.info is file
    filename=Devs.info is file
    filename=Docs.info is file
    filename=Games.info is file
    filename=WBStartup.info is file
    filename=C is file
    filename=L is file
    filename=Libs is file
    filename=Locale is file
    filename=S is file
    filename=Tools is file
    filename=Utilities is file
    filename=WBStartup is file
    filename=Storage.info is file
    filename=Storage is file
    filename=Prefs.info is file
    filename=Tools.info is file
    filename=Utilities.info is file
    filename=Locale.info is file
    filename=Prefs is file
    filename=Applications is file
    filename=Classes is file
    filename=Devs is file
    filename=Docs is file
    filename=Fonts is file
    filename=Games is file
    filename=Emulation is file
    filename=Emulation.info is file


    thanks you.
    BeWorld
    IMac G5 2.1,PowerMac 2.7,PowerBook 1.5
    My MOS ports
  • »29.12.19 - 18:09
    Profile Visit Website
  • MorphOS Developer
    jacadcaps
    Posts: 2042 from 2003/3/5
    From: Canada
    Not "C" but POSIX, really. You didn't tell us whether you've compiled this for libnix or ixemul, by the way.
  • »29.12.19 - 18:20
    Profile Visit Website
  • Order of the Butterfly
    Order of the Butterfly
    beworld
    Posts: 364 from 2010/2/10
    From: FRANCE
    CFLAGS = -02 -Wall
    LIBS= -noixemul

    I use gcc 9 SDK 3.14


    [ Edité par beworld 29.12.2019 - 20:49 ]
    IMac G5 2.1,PowerMac 2.7,PowerBook 1.5
    My MOS ports
  • »29.12.19 - 18:24
    Profile Visit Website
  • MorphOS Developer
    Piru
    Posts: 431 from 2003/2/24
    From: finland, the l...
    stat() is failing and thus 'buf' is random (or rather whatever happens to be in the stack previously). You must check that the stat() return value is 0 before using 'buf'.

    stat() fails because you're not in the correct directory.

    [ Edited by Piru 30.12.2019 - 08:47 ]
  • »29.12.19 - 22:18
    Profile