scandir and file_select()

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Sheldon

    scandir and file_select()

    Hi,

    I have a little warning that I am trying to understand but it escapes
    me. Perhaps someone can help here.
    I have the function read_files() that scans the directory and return
    the desired file names after filtering.
    I have used the function file_select() to filter out unwanted files
    and everything works nicely except that I keep getting the warning:

    "warning: passing argument 3 of 'scandir' from incompatible pointer
    type"

    ********

    int read_files() {
    /* Read directory and find desired files */
    /* file_select is used to sort the files and fetch the desired files
    */
    return scandir(DIR, &list, file_select, alphasort);
    }

    int file_select(str uct direct *entry) {
    if (strstr(entry->d_name,FILTER1 ) && strstr(entry->d_name,FILTER2 )
    && strstr(entry->d_name,FILTER3 )) {
    return TRUE;
    } else {
    return FALSE;
    }
    }


    Can someone enlighten me please!

    /S
  • Richard Heathfield

    #2
    Re: scandir and file_select()

    Sheldon said:
    Hi,
    >
    I have a little warning that I am trying to understand but it escapes
    me. Perhaps someone can help here.
    I have the function read_files() that scans the directory and return
    the desired file names after filtering.
    I have used the function file_select() to filter out unwanted files
    and everything works nicely except that I keep getting the warning:
    >
    "warning: passing argument 3 of 'scandir' from incompatible pointer
    type"
    Then you're passing the wrong kind of argument to scandir.

    In comp.os.linux.d evelopment.apps or possibly comp.unix.progr ammer, I would
    imagine that they'd be able to tell you exactly which kind of argument
    you're supposed to pass.

    <OT>
    In BSD4.3, scandir takes int(*)(const struct dirent **, const struct dirent
    **) as its third argument, whereas alphasort has the prototype int(const
    void *, const void *).
    </OT>

    <snip>

    --
    Richard Heathfield <http://www.cpax.org.uk >
    Email: -http://www. +rjh@
    Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
    "Usenet is a strange place" - dmr 29 July 1999

    Comment

    • Jens Thoms Toerring

      #3
      Re: scandir and file_select()

      Sheldon <shejo284@gmail .comwrote:
      Hi,
      I have a little warning that I am trying to understand but it escapes
      me. Perhaps someone can help here.
      I have the function read_files() that scans the directory and return
      the desired file names after filtering.
      I have used the function file_select() to filter out unwanted files
      and everything works nicely except that I keep getting the warning:
      "warning: passing argument 3 of 'scandir' from incompatible pointer
      type"
      ********
      int read_files() {
      /* Read directory and find desired files */
      /* file_select is used to sort the files and fetch the desired files
      */
      return scandir(DIR, &list, file_select, alphasort);
      }
      int file_select(str uct direct *entry) {
      if (strstr(entry->d_name,FILTER1 ) && strstr(entry->d_name,FILTER2 )
      && strstr(entry->d_name,FILTER3 )) {
      return TRUE;
      } else {
      return FALSE;
      }
      }
      Can someone enlighten me please!
      scandir() isn't a C standard function so you should instead ask in
      comp.unix.progr ammer (I guess that's what you're using, at least
      there is a scandir() function in UNIX that looks familiar to me, if
      that guess is wrong look for a group dealing with your sytem). So
      here's just an (off-topic) hint: under UNIX the file_select() func-
      tion is supposed to take a const struct dirent pointer as its argu-
      ment, note the const qualifier and the difference between the words
      'direct' and 'dirent'.
      Regards, Jens
      --
      \ Jens Thoms Toerring ___ jt@toerring.de
      \______________ ____________ http://toerring.de

      Comment

      • Sheldon

        #4
        Re: scandir and file_select()

        On 20 Aug, 14:33, j...@toerring.d e (Jens Thoms Toerring) wrote:
        Sheldon <shejo...@gmail .comwrote:
        Hi,
        I have a little warning that I am trying to understand but it escapes
        me. Perhaps someone can help here.
        I have the function read_files() that scans the directory and return
        the desired file names after filtering.
        I have used the function file_select() to filter out unwanted files
        and everything works nicely except that I keep getting the warning:
        "warning: passing argument 3 of 'scandir' from incompatible pointer
        type"
        ********
        int read_files() {
        /* Read directory and find desired files */
        /* file_select is used to sort the files and fetch the desired files
        */
        return scandir(DIR, &list, file_select, alphasort);
        }
        int file_select(str uct direct *entry) {
        if (strstr(entry->d_name,FILTER1 ) && strstr(entry->d_name,FILTER2 )
        && strstr(entry->d_name,FILTER3 )) {
        return TRUE;
        } else {
        return FALSE;
        }
        }
        Can someone enlighten me please!
        >
        scandir() isn't a C standard function so you should instead ask in
        comp.unix.progr ammer (I guess that's what you're using, at least
        there is a scandir() function in UNIX that looks familiar to me, if
        that guess is wrong look for a group dealing with your sytem). So
        here's just an (off-topic) hint: under UNIX the file_select() func-
        tion is supposed to take a const struct dirent pointer as its argu-
        ment, note the const qualifier and the difference between the words
        'direct' and 'dirent'.
        Regards, Jens
        --
        \ Jens Thoms Toerring ___ j...@toerring.d e
        \______________ ____________ http://toerring.de
        Thanks guys! I'll go on to the linux group.

        /S

        Comment

        • viza

          #5
          Re: scandir and file_select()

          On Wed, 20 Aug 2008 12:30:15 +0000, Richard Heathfield wrote:
          Sheldon said:
          >"warning: passing argument 3 of 'scandir' from incompatible pointer
          >type"
          >
          Then you're passing the wrong kind of argument to scandir.
          >
          In BSD4.3, scandir takes int(*)(const struct dirent **, const struct
          dirent **) as its third
          fourth
          argument, whereas alphasort has the prototype
          int(const void *, const void *).

          Comment

          • viza

            #6
            Re: scandir and file_select()

            On Wed, 20 Aug 2008 05:03:18 -0700, Sheldon wrote:

            Add:

            int file_select(str uct direct *entry);

            before

            int read_files() {

            Comment

            • Richard Heathfield

              #7
              Re: scandir and file_select()

              viza said:
              On Wed, 20 Aug 2008 12:30:15 +0000, Richard Heathfield wrote:
              >Sheldon said:
              >
              >>"warning: passing argument 3 of 'scandir' from incompatible pointer
              >>type"
              >>
              >Then you're passing the wrong kind of argument to scandir.
              >>
              >In BSD4.3, scandir takes int(*)(const struct dirent **, const struct
              >dirent **) as its third
              >
              fourth
              Oh yes. Thank you. Well, in that case he actually got (at least!) two args
              wrong.

              --
              Richard Heathfield <http://www.cpax.org.uk >
              Email: -http://www. +rjh@
              Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
              "Usenet is a strange place" - dmr 29 July 1999

              Comment

              • Keith Thompson

                #8
                Re: scandir and file_select()

                viza <tom.viza@gm-il.com.obviousc hange.invalidwr ites:
                On Wed, 20 Aug 2008 05:03:18 -0700, Sheldon wrote:
                >
                Add:
                >
                int file_select(str uct direct *entry);
                >
                before
                >
                int read_files() {
                Yes, that could be part of the problem. In the code fragment Sheldon
                posted, there's no visible prototype for file_select at the point
                where its name is used in the call to scandir. In C90 mode, the
                compiler will assume that a function with no visible declaration
                returns int. (C99 dropped implicit int.)

                Also, read_files is declared with no prototype:

                int read_files() { ... }

                This is legal, but rarely a good idea. If it takes no arguments,
                say so:

                int read_files(void ) { ... }

                --
                Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
                Nokia
                "We must do something. This is something. Therefore, we must do this."
                -- Antony Jay and Jonathan Lynn, "Yes Minister"

                Comment

                Working...