Exemple #1
0
/*
** this function will call the compar function with option
*/
int		my_strcmp(t_my_file *s1, t_my_file *s2, char reverse, char *opt)
{
  struct stat	*buf1;
  struct stat	*buf2;
  int		res;

  if (opt[NOTSORT])
    return (0);
  if ((buf1 = malloc(sizeof(*buf1))) == NULL ||
      (buf2 = malloc(sizeof(*buf2))) == NULL)
    my_puterror();
  if ((lstat(my_pathfile(s1->path, s1->name, '\0'), buf1)) == -1)
    my_puterrno(my_pathfile(s1->path, s1->name, '\0'), errno);
  if ((lstat(my_pathfile(s2->path, s2->name, '\0'), buf2)) == -1)
    my_puterrno(my_pathfile(s2->path, s2->name, '\0'), errno);
  if (opt[TIME])
    res = my_strcmp_time(buf1->st_mtime, buf2->st_mtime, reverse);
  else if (opt[SIZE])
    res = my_strcmp_size(buf1->st_size, buf2->st_size, reverse);
  else
    res = my_strcmp_name(s1->name, s2->name, reverse);
  free(buf1);
  free(buf2);
  return (res);
}
Exemple #2
0
void		my_putall_l(char *str, char *path, int *count)
{
  struct stat	*buf;

  if (str[0] != '.')
    {
      buf = my_malloc(sizeof(*buf));
      if ((lstat(my_pathfile(path, str, '\0'), buf)) == -1)
	(void)my_puterrno(my_pathfile(path, str, '\0'), errno);
      else
	*count += (buf->st_blocks / 2);
      free(buf);
    }
}
Exemple #3
0
char		*my_opt_l(char *str, char *opt, t_max *max)
{
    struct stat	*buf;
    int		len;
    char		*link;

    buf = my_malloc(sizeof(*buf));
    link = my_malloc(256 * sizeof(char));
    if ((lstat(str, buf) == -1))
        my_puterrno(str, errno);
    my_putopt_l(buf, ctime(&buf->st_atime), opt, max);
    if (S_ISLNK(buf->st_mode))
    {
        if ((len = readlink(str, link, 256 * sizeof(char))) < 0)
            my_puterrno(str, errno);
        else
            link[len] = '\0';
        free(buf);
        return (link);
    }
    free(buf);
    return (NULL);
}
Exemple #4
0
/*
** This function will count 1 + 1 if 42 = 13
** In fact it will add color that all :(
*/
static char	my_putcolor(char *file, char *path, char *link, char *opt)
{
  struct stat	*buf;

  if ((buf = malloc(sizeof(*buf))) == NULL)
    my_puterror();
  if ((lstat(my_pathfile(path, file, '\0'), buf)) == -1)
    return (my_puterrno(my_pathfile(path, file, '\0'), errno));
  my_printf(opt[QUOTE] ? "\"" : "\0");
  file = opt[DIRC] && !CURR_P(path) ? my_pathfile(path, file, '\0') : file;
  if (my_check_color(file, link, buf, opt) == 1)
    {
      my_printf("\033[1m\033[36m%s\033[0m", file);
      my_printf(opt[QUOTE] ? "\" -> " : " -> ");
      my_putcolor(link, link[0] == '/' ? "\0" : path, NULL, opt);
    }
  else
    my_printf(opt[QUOTE] ? "\"\n" : "\n");
  free(buf);
  return (0);
}