From 2d7e5ae7d83206a60967180c2c51ab56d4f195ae Mon Sep 17 00:00:00 2001 From: patacongo Date: Tue, 12 Feb 2013 14:05:30 +0000 Subject: [PATCH] Preserve access and creation flags with fcntl(F_SETFL) git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@5643 42af7a65-404d-4744-a932-0658087f49c3 --- fs/fs_fcntl.c | 15 +++++++++++++-- include/fcntl.h | 7 +++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/fs/fs_fcntl.c b/fs/fs_fcntl.c index ff53b0f205a..b4d09570568 100644 --- a/fs/fs_fcntl.c +++ b/fs/fs_fcntl.c @@ -1,7 +1,7 @@ /**************************************************************************** * fs/fs_fcntl.c * - * Copyright (C) 2009, 2012 Gregory Nutt. All rights reserved. + * Copyright (C) 2009, 2012-2013 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -49,6 +49,13 @@ #include "fs_internal.h" +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define ACCESS_MODES (O_RDONLY | O_WRONLY | O_RDWR) +#define CREATION_MODES (O_CREAT | O_EXCL | O_APPEND | O_TRUNC) + /**************************************************************************** * Private Functions ****************************************************************************/ @@ -143,7 +150,11 @@ static inline int file_vfcntl(int fildes, int cmd, va_list ap) */ { - this_file->f_oflags = va_arg(ap, int); + int oflags = va_arg(ap, int); + + oflags &= ~(ACCESS_MODES | CREATION_MODES); + this_file->f_oflags &= (ACCESS_MODES | CREATION_MODES); + this_file->f_oflags |= oflags; } break; diff --git a/include/fcntl.h b/include/fcntl.h index 382c5be16b9..0d423a5d064 100644 --- a/include/fcntl.h +++ b/include/fcntl.h @@ -79,6 +79,13 @@ #define _O_MAXBIT 8 +/* Synonyms historically used as F_SETFL flags (BSD). Also FASYNC. */ + +#define FNDELAY O_NONBLOCK +#define FNONBLOCK O_NONBLOCK +#define FAPPEND O_APPEND +#define FSYNC O_SYNC + /* fcntl() commands */ #define F_DUPFD 0 /* Duplicate a file descriptor */