/*
 * This file is part of "VirtuaMUnstaz Demo Distribution".
 *
 * This is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2, or (at your option)
 * any later version.
 *
 * "VirtuaMUnstaz Demo Distribution" is distributed in the hope that it will be 
 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this software; see the file COPYING.  If not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

/* $Id: util.c,v 2.2 2000/03/15 06:41:54 leo Exp $ */

#include <unistd.h>

/**
 * clear an array of bytes
 */
extern void clear(char *array, const int size) {
  int i;
  for(i = size - 1; i >= 0; i--)
    array[i] = 0x00;
}

/**
 * get the base name of a fully qualified file name
 * this method simply copies the file name if there is no path
 */
extern char *basename(char *file) {
  char *ptr = (char *)strrchr(file, '/');
  if(ptr != NULL) return (char *)strdup(ptr + 1);
  return (char *)strdup(file);
}

/**
 * get the file name out of a fully qualified file name
 */
extern char *pathname(char *file) {
  char *ptr = (char *)strrchr(file, '/');
  if(ptr != NULL) {
    char *path = (char *)malloc(ptr - file + 2);
    strncpy(path, file, ptr - file + 1);
    path[ptr - file + 1] = 0x00;
    return path;
  } else {
    char *tmp = (char *)malloc(1);
    *tmp = 0x00;
    return tmp;
  }
}
