TIP: Click on subject to list as thread! ANSI
echo: public_domain
to: All
from: Paul Edwards
date: 1995-07-28 00:43:44
subject: delzero.c

/*********************************************************************/
/*                                                                   */
/*  This Program Written by Paul Edwards, 3:711/934{at}fidonet.         */
/*  Released to the Public Domain                                    */
/*                                                                   */
/*********************************************************************/
/*********************************************************************/
/*                                                                   */
/*  delzero - delete zero-length files                               */
/*                                                                   */
/*********************************************************************/

#include 
#include 

#include "trav.h"

static int delzero(char *file, void *ucb);

int main(int argc, char **argv)
{
    int ret;
    
    if (argc < 2)
    {
        printf("usage: delzero \n");
        return (EXIT_FAILURE);
    }
    ret = trav(*(argv+1), NULL, delzero, NULL);
    if (!ret)
    {
        ret = EXIT_FAILURE;
    }
    else
    {
        ret = EXIT_SUCCESS;
    }
    return (ret);
}

static int delzero(char *file, void *ucb)
{
    FILE *fp;
    
    (void)ucb;
    fp = fopen(file, "rb");
    if (fp == NULL)
    {
        printf("failed to open file %s - aborting\n", file);
        return (0);
    }
    fgetc(fp);
    if (ferror(fp))
    {
        printf("file error on file %s - aborting\n", file);
        return (0);
    }
    if (feof(fp))
    {
        fclose(fp);
        if (remove(file) != 0)
        {
            printf("failed to remove file %s - aborting\n", file);
            return (0);
        }
    }
    else
    {
        fclose(fp);
    }
    return (1);
}
@EOT:

---
* Origin: X (3:711/934.9)

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.