| iMatix home page
| << | < | > | >>
SFL Logo SFL
Version 2.11

 

fix_dir

#include "sfldir.h"
int
fix_dir (DIRST *dir)

Synopsis

Converts all strings in the DIRST into permenant values, by allocating heap memory for each string. You must call this function if you intend to keep a set of DIRSTs, for searching or sorting. You do not need to call fix dir() if you handle each call to read dir() independently. If you use fix dir(), you must call free dir() for each DIRST when you terminate. Returns 0 if okay, -1 if there was insufficient memory or another fatal error.

Source Code - (sfldir.c)

{
    char
        *owner,
        *group,
        *file_name;

    /*  Allocate each string                                                 */
    owner     = mem_strdup (dir-> owner);
    group     = mem_strdup (dir-> group);
    file_name = mem_strdup (dir-> file_name);

    /*  If all okay, assign new strings and indicate everything okay         */
    if (owner && group && file_name)
      {
        dir-> owner     = owner;
        dir-> group     = group;
        dir-> file_name = file_name;
        dir-> _fixed    = TRUE;
        return (0);
      }
    else
      {
        /*  Otherwise patch things back the way they were                    */
        if (owner)
            mem_free (owner);
        if (group)
            mem_free (group);
        if (file_name)
            mem_free (file_name);
        return (-1);
      }
}

| << | < | > | >> iMatix Copyright © 1996-2000 iMatix Corporation