rm simulation

    0

    0

    Giovanny Gongora

    Codiga's C Recipes

    Simulate the rm command

    #include <fcntl.h>
    #include <stdio.h>
    #include <stdlib.h>
    
    int rm() {
    	int fd;
    	if (argc != 2) {
    		printf("Number of Arguements provided != 2 \n");
    		printf("Arguements Required: \n");
    		printf("Filename \n");
    		exit(-1);
    	}
    	fd = open(argv[1], O_RDONLY);
    	if (fd != -1) {
    		close(fd);
    		unlink(argv[1]);
    		printf("%s deleted! \n", argv[1]);
    	}
    	else {
    		perror(argv[1]);
    	}
    	return 0;
    }
    
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Explore
    • Cookbooks
    • Playground
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.