File: log.c

package info (click to toggle)
xshipwars 1.32-5
  • links: PTS
  • area: main
  • in suites: potato
  • size: 17,176 kB
  • ctags: 6,357
  • sloc: ansic: 157,152; makefile: 226; sh: 75
file content (56 lines) | stat: -rw-r--r-- 934 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
                            Logging

	Functions:

	int LogAppendLineFormatted(char *filename, char *str)

	---


 */

#include "xsw.h"



int LogAppendLineFormatted(char *filename, char *str)
{
	FILE *fp;
	int len, bytes_written;


	/* Make sure str is valid. */
	if((filename == NULL) ||
	   (str == NULL)
	)
	    return(-1);
	else if(str[0] == '\0')
	    return(0);


	/* ************************************************************ */

        /* Open or create file for appending. */
        fp = fopen(filename, "a");
        if(fp == NULL)
        {
            fprintf(stderr,
                "%s: Cannot open or create.\n",
                filename
            );
            return(-1);
        }

	/* Append the line. */
	len = strlen(str);
        bytes_written = fwrite(str, sizeof(char), len, fp);

	/* Close the file. */
	fclose(fp);
	fp = NULL;


	/* Return the number of bytes written. */
	return(bytes_written);
}