[gcompris-devel] gcompris 2.3 solaris

roberto dircio rdircio at yahoo.com
Tue Jun 3 15:35:14 UTC 2003


hi, for the first time!

In response to dave lopata's and other's need for
gcompris in solaris, i attach inline files for the
definition of scandir,alphasort,and setenv....
which have been renamed as myscandir,myalphasort...
procedure:
- put myscandir.c and myscandir.h inside src/gcompris 
- include myscandir.h in all files that make use of
scandir,alphasort, or setenv.
- substitute all calls to "scandir", and "alphasort"
to "myscandir" and "myalphasort",
- force them to be built before everything, and voila!

I would suggest rather using non-bsd things for this.
  portability!

--- Roberto Dircio Palacios Macedo

--------------------begin-------myscandir.h---------
//---- an implementation of scandir
int myscandir(const char *dir, struct dirent
***namelist,int (*select)(const struct dirent *),int
(*compar)(const struct dirent **, const struct dirent
**));

//--- an implementation of alphasort
int myalphasort(const struct dirent **a, const struct
dirent **b);

//--- an implementation of setenv
int setenv(char *name, char *value,int clobber);

--------------------end-------myscandir.h-----------

--------------------begin-------myscandir.c-----------
#include<dirent.h>
#include<stdlib.h>
#include<string.h>
#include<sys/types.h>

//---- an implementation of scandir
int myscandir(const char *dir, struct dirent
***namelist,int (*select)(const struct dirent *),int
(*compar)(const struct dirent **, const struct dirent
**))
{
  DIR *d;
  struct dirent *entry;
  register int i=0;
  size_t entrysize;

  if ((d=opendir(dir)) == NULL)
     return(-1);

  *namelist=NULL;
  while ((entry=readdir(d)) != NULL)
  {
    if (select == NULL || (select != NULL &&
(*select)(entry)))
    {
      *namelist=(struct dirent **)realloc((void
*)(*namelist),
                 (size_t)((i+1)*sizeof(struct dirent
*)));
        if (*namelist == NULL) return(-1);
        entrysize=sizeof(struct
dirent)-sizeof(entry->d_name)+strlen(entry->d_name)+1;
        (*namelist)[i]=(struct dirent
*)malloc(entrysize);
        if ((*namelist)[i] == NULL) return(-1);
        memcpy((*namelist)[i], entry, entrysize);
        i++;
    }
  }
  if (closedir(d)) return(-1);
  if (i == 0) return(-1);
  if (compar != NULL)
    qsort((void *)(*namelist), (size_t)i,
sizeof(struct dirent *),compar); 

  return(i);
}

//--- an implementation of alphasort
int myalphasort(const struct dirent **a, const struct
dirent **b)
{
  return(strcmp((*a)->d_name, (*b)->d_name));
}

//---- an implementation of setenv
int setenv(char *name, char *value,int clobber)
{
        char *malloc();
        char *getenv();
        char *cp;

        if (clobber == 0 && getenv(name) != 0)
                return(0);
        if ((cp = malloc(strlen(name) + strlen(value)
+2)) == 0)
                return(1);
        sprintf(cp, "%s=%s",name,value);
        return(putenv(cp));
} 

--------------------end-------myscandir.c-------------


--- Roberto Dircio Palacios Macedo


__________________________________
Do you Yahoo!?
Yahoo! Calendar - Free online calendar with sync to Outlook(TM).
http://calendar.yahoo.com




More information about the Gcompris-devel mailing list