changeset 1621:26840b464238

* src/tftp_server.c: files are now created with the O_CREAT|O_TRUNC|O_WRONLY so it is possible to write to non-existing files and that overwriting a larger file with a smaller file does not leave a garbage at the end.
author jlarmour
date Thu, 29 Apr 2004 07:19:57 +0000
parents d04fae1f5cde
children 812bf7d5e7fc
files packages/net/common/current/ChangeLog packages/net/common/current/src/tftp_server.c
diffstat 2 files changed, 9 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/packages/net/common/current/ChangeLog
+++ b/packages/net/common/current/ChangeLog
@@ -1,3 +1,10 @@
+2004-04-19  Oyvind Harboe <oyvind.harboe@zylin.com>
+
+	* src/tftp_server.c: files are now created with the
+	O_CREAT|O_TRUNC|O_WRONLY so it is possible to write to
+	non-existing files and that overwriting a larger file with
+	a smaller file does not leave a garbage at the end.
+
 2004-04-19  John Dallaway  <jld@ecoscentric.com>
 
 	* doc/tcpip.sgml: Remove reference to RedBoot documentation
--- a/packages/net/common/current/src/tftp_server.c
+++ b/packages/net/common/current/src/tftp_server.c
@@ -59,6 +59,7 @@
 #include <tftp_support.h>     // TFTPD structures
 #include <cyg/kernel/kapi.h>
 #include <stdlib.h>           // For malloc
+#include <fcntl.h>
 
 #define nCYGOPT_NET_TFTP_SERVER_INSTRUMENT
 #ifdef CYGOPT_NET_TFTP_SERVER_INSTRUMENT
@@ -264,7 +265,7 @@ tftpd_write_file(struct tftp_server *ser
 	freeaddrinfo(res);
         return;
     }
-    if ((fd = (server->ops->open)(hdr->th_stuff, O_WRONLY)) < 0) {
+    if ((fd = (server->ops->open)(hdr->th_stuff, O_WRONLY|O_TRUNC|O_CREAT)) < 0) {
         tftpd_send_error(s,reply,TFTP_ENOTFOUND,from_addr, from_len);
         close(s);
 	freeaddrinfo(res);