<commit_before>#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
int main()
{

    /* Work in progress version fromn 9/1 lecture. doesn't do much yet */

    int sourcefile = open("string.c", O_RDONLY);
    if (sourcefile == -1) {
	perror("open source file failed");
	exit(1);
    }

    /* what happens if we omit O_CREAT? what about modes? */
    int destfile = open("copyofstring.c", O_WRONLY | O_CREAT | O_TRUNC,
			S_IRUSR | S_IWUSR);
    if (destfile == -1) {
	perror("open dest file failed");
	exit(2);
    }

    /* first version will only copy first 100 bytes of source */
    ssize_t rret = 0;
    ssize_t wret = 0;
    char buf[1024];

    while ((rret = read(sourcefile, buf, 1024))) {
	if (rret == -1) {
	    perror("read error");
	    exit(3);
	}

	/* keep in mind that write is not required
	 * to write the full amount - BUG */
	wret = write(destfile, buf, rret);
	if (wret == -1) {
	    perror("write error");
	    exit(4);
	}
    }
    /* explicit close isn't useful if you dont check its return... */
    close(sourcefile);
    close(destfile);<commit_msg>added ability to read arguments from cli<commit_after>#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char ** argv)
{

    if (argc != 3) {
        printf("wrong number of arguments\n");
        exit(5);
    }

    int sourcefile = open(argv[1], O_RDONLY);
    if (sourcefile == -1) {
	perror("open source file failed");
	exit(1);
    }

    /* what happens if we omit O_CREAT? what about modes? */
    int destfile = open(argv[2], O_WRONLY | O_CREAT | O_TRUNC,
			S_IRUSR | S_IWUSR);
    if (destfile == -1) {
	perror("open dest file failed");
	exit(2);
    }

    /* first version will only copy first 100 bytes of source */
    ssize_t rret = 0;
    ssize_t wret = 0;
    char buf[1024];
    int iterations = 0;

    while ((rret = read(sourcefile, buf, 1024))) {
	if (rret == -1) {
	    perror("read error");
	    exit(3);
	}

	/* keep in mind that write is not required
	 * to write the full amount - BUG */
	wret = write(destfile, buf, rret);
	if (wret == -1) {
	    perror("write error");
	    exit(4);
	}

        printf("loop iteration %d\n", iterations);
        iterations++;
    }
    /* explicit close isn't useful if you dont check its return... */
    close(sourcefile);
    close(destfile);
{'fraction_non_alphanumeric': 0.1503267973856209, 'fraction_numerical': 0.020016339869281044, 'mean_word_length': 2.7275494672754945, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5963932', 'n_tokens_mistral': 943, 'n_tokens_neox': 875, 'n_words': 267}