Skip to content

Commit

Permalink
rewrite error messages to lower case
Browse files Browse the repository at this point in the history
  • Loading branch information
uno20001 committed Apr 19, 2020
1 parent dbac267 commit bda165d
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 47 deletions.
20 changes: 10 additions & 10 deletions ftw.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ static struct dir_state *dir_state_new(struct dir_state *prev,
struct dir_state *ds = malloc(sizeof(struct dir_state));

if (ds == NULL) {
fprintf(stderr, "Out of memory.\n");
fprintf(stderr, "fatal error: out of memory\n");
return NULL;
}

Expand All @@ -61,7 +61,7 @@ static unsigned int dir_state_open(struct dir_state *ds, const char *name,
{
ds->dir = opendir(name);
if (ds->dir == NULL) {
fprintf(stderr, "Error opening '%s': %s\n",
fprintf(stderr, "fatal error: cannot open '%s': %s\n",
name, strerror(errno));
return 1;
}
Expand All @@ -76,7 +76,7 @@ static unsigned int dir_state_reopen(struct dir_state *ds, char *name)
name[ds->length] = '\0';
ds->dir = opendir(name);
if (ds->dir == NULL) {
fprintf(stderr, "Error opening '%s': %s\n",
fprintf(stderr, "fatal error: cannot open '%s': %s\n",
name, strerror(errno));
return 1;
}
Expand All @@ -92,13 +92,13 @@ static unsigned int dir_state_close(struct dir_state *ds)
{
ds->offset = telldir(ds->dir);
if (ds->offset < 0) {
fprintf(stderr, "Error getting dir offset: %s\n",
fprintf(stderr, "fatal error: cannot obtain dir offset: %s\n",
strerror(errno));
return 1;
}

if (closedir(ds->dir)) {
fprintf(stderr, "Error closing directory: %s\n",
fprintf(stderr, "fatal error: cannot close directory: %s\n",
strerror(errno));
return 1;
}
Expand Down Expand Up @@ -141,7 +141,7 @@ EXPORT int file_tree_walk(const char *dirname, unsigned int nfds,

path = malloc(path_size);
if (path == NULL) {
fprintf(stderr, "Out of memory.\n");
fprintf(stderr, "fatal error: out of memory\n");
return cleanup(ds, NULL, -1);
}
path_max = path + path_size;
Expand All @@ -156,7 +156,7 @@ EXPORT int file_tree_walk(const char *dirname, unsigned int nfds,

new_path = realloc(path, 2*path_size);
if (new_path == NULL) {
fprintf(stderr, "Out of memory.\n");
fprintf(stderr, "fatal error: out of memory\n");
return cleanup(ds, path, -1);
}
end = new_path + path_size;
Expand Down Expand Up @@ -205,7 +205,7 @@ EXPORT int file_tree_walk(const char *dirname, unsigned int nfds,

new_path = realloc(path, 2*path_size);
if (new_path == NULL) {
fprintf(stderr, "Out of memory.\n");
fprintf(stderr, "fatal error: out of memory\n");
return cleanup(ds, path, -1);
}
end = new_path + path_size;
Expand All @@ -216,7 +216,7 @@ EXPORT int file_tree_walk(const char *dirname, unsigned int nfds,
}

if (stat(path, &sbuf)) {
fprintf(stderr, "Error stat'ing '%s': %s\n",
fprintf(stderr, "fatal error: cannot stat '%s': %s\n",
path, strerror(errno));
return cleanup(ds, path, -1);
}
Expand Down Expand Up @@ -249,7 +249,7 @@ EXPORT int file_tree_walk(const char *dirname, unsigned int nfds,
} else {
if (closedir(ds->dir)) {
path[ds->length] = '\0';
fprintf(stderr, "Error closing '%s': %s\n",
fprintf(stderr, "fatal error: cannot close '%s': %s\n",
path, strerror(errno));
return cleanup(ds, path, -1);
}
Expand Down
12 changes: 6 additions & 6 deletions hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ EXPORT unsigned char *make_hash(struct metafile *m)
read_buf = malloc(m->piece_length);

/* check if we've run out of memory */
FATAL_IF0(hash_string == NULL || read_buf == NULL, "Out of memory.\n");
FATAL_IF0(hash_string == NULL || read_buf == NULL, "out of memory\n");

/* initiate pos to point to the beginning of hash_string */
pos = hash_string;
Expand All @@ -87,7 +87,7 @@ EXPORT unsigned char *make_hash(struct metafile *m)

/* open the current file for reading */
FATAL_IF((fd = open(f->path, OPENFLAGS)) == -1,
"Error opening '%s' for reading: %s\n", f->path, strerror(errno));
"cannot open '%s' for reading: %s\n", f->path, strerror(errno));
printf("Hashing %s.\n", f->path);
fflush(stdout);

Expand All @@ -97,7 +97,7 @@ EXPORT unsigned char *make_hash(struct metafile *m)
to the end of the file */
while (1) {
ssize_t d = read(fd, read_buf + r, m->piece_length - r);
FATAL_IF(d < 0, "Error reading from '%s': %s\n",
FATAL_IF(d < 0, "cannot read from '%s': %s\n",
f->path, strerror(errno));

if (d == 0) /* end of file */
Expand All @@ -118,7 +118,7 @@ EXPORT unsigned char *make_hash(struct metafile *m)
}

/* now close the file */
FATAL_IF(close(fd), "Error closing '%s': %s\n",
FATAL_IF(close(fd), "cannot close '%s': %s\n",
f->path, strerror(errno));
}

Expand All @@ -132,8 +132,8 @@ EXPORT unsigned char *make_hash(struct metafile *m)
#ifndef NO_HASH_CHECK
counter += r;
FATAL_IF(counter != m->size,
"Counted %" PRId64 " bytes, but hashed %" PRId64 " bytes. "
"Something is wrong...\n",
"counted %" PRId64 " bytes, but hashed %" PRId64 " bytes; "
"something is wrong...\n",
m->size, counter);
#endif

Expand Down
26 changes: 13 additions & 13 deletions hash_pthreads.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ static struct piece *get_free(struct queue *q, size_t piece_length)
q->free = r->next;
} else if (q->buffers < q->buffers_max) {
r = malloc(sizeof(struct piece) - 1 + piece_length);
FATAL_IF0(r == NULL, "Out of memory.\n");
FATAL_IF0(r == NULL, "out of memory\n");


q->buffers++;
Expand Down Expand Up @@ -171,7 +171,7 @@ static void *print_progress(void *data)
int err;

err = pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
FATAL_IF(err, "Error setting thread cancel type: %s\n", strerror(err));
FATAL_IF(err, "cannot set thread cancel type: %s\n", strerror(err));

while (1) {
/* print progress and flush the buffer immediately */
Expand Down Expand Up @@ -217,12 +217,12 @@ static void read_files(struct metafile *m, struct queue *q, unsigned char *pos)

/* open the current file for reading */
FATAL_IF((fd = open(f->path, OPENFLAGS)) == -1,
"Error opening '%s' for reading: %s\n", f->path, strerror(errno));
"cannot open '%s' for reading: %s\n", f->path, strerror(errno));

while (1) {
ssize_t d = read(fd, p->data + r, m->piece_length - r);

FATAL_IF(d < 0, "Error reading from '%s': %s\n",
FATAL_IF(d < 0, "cannot read from '%s': %s\n",
f->path, strerror(errno));

if (d == 0) /* end of file */
Expand All @@ -244,7 +244,7 @@ static void read_files(struct metafile *m, struct queue *q, unsigned char *pos)
}

/* now close the file */
FATAL_IF(close(fd), "Error closing '%s': %s\n",
FATAL_IF(close(fd), "cannot close '%s': %s\n",
f->path, strerror(errno));
}

Expand All @@ -259,8 +259,8 @@ static void read_files(struct metafile *m, struct queue *q, unsigned char *pos)
#ifndef NO_HASH_CHECK
counter += r;
FATAL_IF(counter != m->size,
"Counted %" PRId64 " bytes, but hashed %" PRId64 " bytes. "
"Something is wrong...\n",
"counted %" PRId64 " bytes, but hashed %" PRId64 " bytes; "
"something is wrong...\n",
m->size, counter);
#endif
}
Expand All @@ -283,42 +283,42 @@ EXPORT unsigned char *make_hash(struct metafile *m)

workers = malloc(m->threads * sizeof(pthread_t));
hash_string = malloc(m->pieces * SHA_DIGEST_LENGTH);
FATAL_IF0(workers == NULL || hash_string == NULL, "Out of memory.\n");
FATAL_IF0(workers == NULL || hash_string == NULL, "out of memory\n");

q.pieces = m->pieces;
q.buffers_max = 3*m->threads;

/* create worker threads */
for (i = 0; i < m->threads; i++) {
err = pthread_create(&workers[i], NULL, worker, &q);
FATAL_IF(err, "Error creating thread: %s\n", strerror(err));
FATAL_IF(err, "cannot create thread: %s\n", strerror(err));
}

/* now set off the progress printer */
err = pthread_create(&print_progress_thread, NULL, print_progress, &q);
FATAL_IF(err, "Error creating thread: %s\n", strerror(err));
FATAL_IF(err, "cannot create thread: %s\n", strerror(err));

/* read files and feed pieces to the workers */
read_files(m, &q, hash_string);

/* we're done so stop printing our progress. */
err = pthread_cancel(print_progress_thread);
FATAL_IF(err, "Error cancelling thread: %s\n", strerror(err));
FATAL_IF(err, "cannot cancel thread: %s\n", strerror(err));

/* inform workers we're done */
set_done(&q);

/* wait for workers to finish */
for (i = 0; i < m->threads; i++) {
err = pthread_join(workers[i], NULL);
FATAL_IF(err, "Error joining thread: %s\n", strerror(err));
FATAL_IF(err, "cannot join thread: %s\n", strerror(err));
}

free(workers);

/* the progress printer should be done by now too */
err = pthread_join(print_progress_thread, NULL);
FATAL_IF(err, "Error joining thread: %s\n", strerror(err));
FATAL_IF(err, "cannot join thread: %s\n", strerror(err));

/* destroy mutexes and condition variables */
pthread_mutex_destroy(&q.mutex_full);
Expand Down
30 changes: 15 additions & 15 deletions init.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ static void set_absolute_file_path(struct metafile *m)
using getcwd is a bit of a PITA */
/* allocate initial string */
string = malloc(length);
FATAL_IF0(string == NULL, "Out of memory.\n");
FATAL_IF0(string == NULL, "out of memory\n");

/* while our allocated memory for the working dir isn't big enough */
while (getcwd(string, length) == NULL) {
Expand All @@ -93,7 +93,7 @@ static void set_absolute_file_path(struct metafile *m)
free(string);
/* and allocate a new one twice as big muahaha */
string = malloc(length);
FATAL_IF0(string == NULL, "Out of memory.\n");
FATAL_IF0(string == NULL, "out of memory\n");
}

/* now set length to the proper length of the working dir */
Expand All @@ -103,14 +103,14 @@ static void set_absolute_file_path(struct metafile *m)
/* append <torrent name>.torrent to the working dir */
string =
realloc(string, length + strlen(m->torrent_name) + 10);
FATAL_IF0(string == NULL, "Out of memory.\n");
FATAL_IF0(string == NULL, "out of memory\n");
sprintf(string + length, DIRSEP "%s.torrent", m->torrent_name);
} else {
/* otherwise append the torrent path to the working dir */
string =
realloc(string,
length + strlen(m->metainfo_file_path) + 2);
FATAL_IF0(string == NULL, "Out of memory.\n");
FATAL_IF0(string == NULL, "out of memory\n");
sprintf(string + length, DIRSEP "%s", m->metainfo_file_path);
}

Expand All @@ -128,7 +128,7 @@ static slist_t *get_slist(char *s)

/* allocate memory for the first node in the list */
list = last = malloc(sizeof(slist_t));
FATAL_IF0(list == NULL, "Out of memory.\n");
FATAL_IF0(list == NULL, "out of memory\n");

/* add URLs to the list while there are commas in the string */
while ((e = strchr(s, ','))) {
Expand All @@ -143,7 +143,7 @@ static slist_t *get_slist(char *s)
/* append another node to the list */
last->next = malloc(sizeof(slist_t));
last = last->next;
FATAL_IF0(last == NULL, "Out of memory.\n");
FATAL_IF0(last == NULL, "out of memory\n");
}

/* set the last string in the list */
Expand All @@ -163,7 +163,7 @@ static int is_dir(struct metafile *m, char *target)
struct stat s; /* stat structure for stat() to fill */

/* stat the target */
FATAL_IF(stat(target, &s), "Error stat'ing '%s': %s\n",
FATAL_IF(stat(target, &s), "cannot stat '%s': %s\n",
target, strerror(errno));

/* if it is a directory, just return 1 */
Expand All @@ -177,7 +177,7 @@ static int is_dir(struct metafile *m, char *target)
/* since we know the torrent is just a single file and we've
already stat'ed it, we might as well set the file list */
m->file_list = malloc(sizeof(flist_t));
FATAL_IF0(m->file_list == NULL, "Out of memory.\n");
FATAL_IF0(m->file_list == NULL, "out of memory\n");
m->file_list->path = target;
m->file_list->size = s.st_size;
m->file_list->next = NULL;
Expand Down Expand Up @@ -229,7 +229,7 @@ static int process_node(const char *path, const struct stat *sb, void *data)
new_node = malloc(sizeof(flist_t));
if (new_node == NULL ||
(new_node->path = strdup(path)) == NULL) {
fprintf(stderr, "Out of memory.\n");
fprintf(stderr, "fatal error: out of memory\n");
return -1;
}
new_node->size = sb->st_size;
Expand Down Expand Up @@ -429,7 +429,7 @@ EXPORT void init(struct metafile *m, int argc, char *argv[])
announce_last = announce_last->next;

}
FATAL_IF0(announce_last == NULL, "Out of memory.\n");
FATAL_IF0(announce_last == NULL, "out of memory\n");
announce_last->l = get_slist(optarg);
break;
case 'c':
Expand Down Expand Up @@ -477,28 +477,28 @@ EXPORT void init(struct metafile *m, int argc, char *argv[])
web_seed_last = web_seed_last->next;
break;
case '?':
fatal("Use -h for help.\n");
fatal("use -h for help.\n");
}
}

/* set the correct piece length.
default is 2^18 = 256kb. */
FATAL_IF0(m->piece_length < 15 || m->piece_length > 28,
"The piece length must be a number between 15 and 28.\n");
"the piece length must be a number between 15 and 28.\n");
m->piece_length = 1 << m->piece_length;

if (announce_last != NULL)
announce_last->next = NULL;

/* ..and a file or directory from which to create the torrent */
FATAL_IF0(optind >= argc,
"Must specify the contents, use -h for help\n");
"must specify the contents, use -h for help\n");

#ifdef USE_PTHREADS
/* check the number of threads */
if (m->threads) {
FATAL_IF0(m->threads > 20,
"The number of threads is limited to at most 20\n");
"the number of threads is limited to at most 20\n");
} else {
#ifdef _SC_NPROCESSORS_ONLN
m->threads = sysconf(_SC_NPROCESSORS_ONLN);
Expand Down Expand Up @@ -527,7 +527,7 @@ EXPORT void init(struct metafile *m, int argc, char *argv[])
m->target_is_directory = is_dir(m, argv[optind]);
if (m->target_is_directory) {
/* change to the specified directory */
FATAL_IF(chdir(argv[optind]), "Error changing directory to '%s': %s\n",
FATAL_IF(chdir(argv[optind]), "cannot change directory to '%s': %s\n",
argv[optind], strerror(errno));

if (file_tree_walk("." DIRSEP, MAX_OPENFD, process_node, m))
Expand Down
6 changes: 3 additions & 3 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@ static FILE *open_file(const char *path)
/* open and create the file if it doesn't exist already */
fd = open(path, O_WRONLY | O_BINARY | O_CREAT | O_EXCL,
S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
FATAL_IF(fd < 0, "Error creating '%s': %s\n", path, strerror(errno));
FATAL_IF(fd < 0, "cannot create '%s': %s\n", path, strerror(errno));

/* create the stream from this filedescriptor */
f = fdopen(fd, "wb");
FATAL_IF(f == NULL, "Error creating stream for '%s': %s\n",
FATAL_IF(f == NULL, "cannot create stream for '%s': %s\n",
path, strerror(errno));

return f;
Expand All @@ -93,7 +93,7 @@ static FILE *open_file(const char *path)
static void close_file(FILE *f)
{
/* close the metainfo file */
FATAL_IF(fclose(f), "Error closing stream: %s\n", strerror(errno));
FATAL_IF(fclose(f), "cannot close stream: %s\n", strerror(errno));
}

/*
Expand Down

0 comments on commit bda165d

Please sign in to comment.