Revision 3245 libsylph/utils.c

View differences:

utils.c
1 1
/*
2 2
 * LibSylph -- E-Mail client library
3
 * Copyright (C) 1999-2012 Hiroyuki Yamamoto
3
 * Copyright (C) 1999-2013 Hiroyuki Yamamoto
4 4
 *
5 5
 * This library is free software; you can redistribute it and/or
6 6
 * modify it under the terms of the GNU Lesser General Public
......
3123 3123
	return 0;
3124 3124
}
3125 3125

  
3126
gint copy_file_stream(FILE *fp, FILE *dest_fp)
3127
{
3128
	gint n_read;
3129
	gchar buf[BUFFSIZE];
3130

  
3131
	g_return_val_if_fail(fp != NULL, -1);
3132
	g_return_val_if_fail(dest_fp != NULL, -1);
3133

  
3134
	while ((n_read = fread(buf, sizeof(gchar), sizeof(buf), fp)) > 0) {
3135
		if (n_read < sizeof(buf) && ferror(fp))
3136
			break;
3137
		if (fwrite(buf, n_read, 1, dest_fp) < 1) {
3138
			g_warning("copy_file_stream: writing to file failed.\n");
3139
			return -1;
3140
		}
3141
	}
3142

  
3143
	if (ferror(fp)) {
3144
		perror("fread");
3145
		return -1;
3146
	}
3147
	if (fflush(dest_fp) == EOF) {
3148
		FILE_OP_ERROR("copy_file_stream", "fflush");
3149
		return -1;
3150
	}
3151

  
3152
	return 0;
3153
}
3154

  
3126 3155
/* convert line endings into CRLF. If the last line doesn't end with
3127 3156
 * linebreak, add it.
3128 3157
 */

Also available in: Unified diff