Database/db.c
int db_print(char *filename) {
    FILE *out;
    if (filename == NULL) {
        db_print_recurs(&head, 0, stdout);
        return 0;
    }

    // skip over leading whitespace
    while (isspace(*filename)) {
        filename++;
    }

    if (*filename == '\0') {
		pthread_mutex_lock (&db_mutex);

        db_print_recurs(&head, 0, stdout);
		
		pthread_mutex_unlock (&db_mutex);

        return 0;
    }

    if ((out = fopen(filename, "w+")) == NULL) {
        return -1;
    }

	pthread_mutex_lock (&db_mutex);
    db_print_recurs(&head, 0, out);
	pthread_mutex_unlock (&db_mutex);
    
	fclose(out);

    return 0;
}
/* Prints the whole database, using db_print_recurs, to a file with
 * the given filename, or to stdout if the filename is empty or NULL.
 * If the file does not exist, it is created. The file is truncated
 * in all cases.
 *
 * Returns 0 on success, or -1 if the file could not be opened
 * for writing. */
Prints the whole database, using db_print_recurs, to a file with
the given filename, or to stdout if the filename is empty or NULL.
If the file does not exist, it is created. The file is truncated
in all cases.

Returns 0 on success, or -1 if the file could not be opened
for writing.
Prints the whole database using db_print_recurs to a file with the given filename or to stdout if the filename is empty or NULL . If the file does not exist it is created . The file is truncated in all cases . Returns 0 on success or - 1 if the file could not be opened for writing .
int db_print(char *filename) {
    FILE *out;
    if (filename == NULL) {
        db_print_recurs(&head, 0, stdout);
        return 0;
    }
    while (isspace(*filename)) {
        filename++;
    }
    if (*filename == '\0') {
		pthread_mutex_lock (&db_mutex);
        db_print_recurs(&head, 0, stdout);
		pthread_mutex_unlock (&db_mutex);
        return 0;
    }
    if ((out = fopen(filename, "w+")) == NULL) {
        return -1;
    }
	pthread_mutex_lock (&db_mutex);
    db_print_recurs(&head, 0, out);
	pthread_mutex_unlock (&db_mutex);
	fclose(out);
    return 0;
}
int db_print ( char * filename ) { FILE * out ; if ( filename == NULL ) { db_print_recurs ( & head , 0 , stdout ) ; return 0 ; } while ( isspace ( * filename ) ) { filename ++ ; } if ( * filename == ' \0 ' ) { pthread_mutex_lock ( & db_mutex ) ; db_print_recurs ( & head , 0 , stdout ) ; pthread_mutex_unlock ( & db_mutex ) ; return 0 ; } if ( ( out = fopen ( filename , " " ) ) == NULL ) { return -1 ; } pthread_mutex_lock ( & db_mutex ) ; db_print_recurs ( & head , 0 , out ) ; pthread_mutex_unlock ( & db_mutex ) ; fclose ( out ) ; return 0 ; }
Prints the whole database, using db_print_recurs, to a file with
 the given filename, or to stdout if the filename is empty or NULL.
Prints the whole database using db_print_recurs to a file with the given filename or to stdout if the filename is empty or NULL .
// skip over leading whitespace