- char cwd[PATH_MAX];
- char *path, *fname, *tmp;
- size_t fname_len;
- ssize_t r;
- /* If the user provided the output directory where she wishes
- to save the receipt, then we use it. Otherwise, we save
- the file in the current working directory (CWD). */
- if (args->output_dir == NULL)
- path = getcwd(cwd, PATH_MAX);
- else {
- struct stat st;
- if (stat(args->output_dir, &st) < 0) {
- fprintf(stderr, "Could not stat directory \"%s\": %s\n", args->output_dir, strerror(errno));
- return;
- }
- if (!S_ISDIR(st.st_mode)) {
- fprintf(stderr, "Error: \"%s\" is a not a directory.\n", args->output_dir);
- return;
- }
- path = args->output_dir;
- }