1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/genericopenlibs/openenvcore/libc/src/creat.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,73 @@
1.4 +// Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +//
1.19 +
1.20 +
1.21 +#include <sys/errno.h>
1.22 +#include <stdlib.h>
1.23 +#include <fcntl.h>
1.24 +#include "sysreent.h"
1.25 +
1.26 +// -----------------------------------------------------------------------------
1.27 +// Creat : Function that stub which
1.28 +
1.29 +// This function takes the system call number and that transforms
1.30 +// controll to the respective routines that performs the task
1.31 +// requested .
1.32 +// Returns: -1: if the requested task fails
1.33 +// 0: if the requested task successfull
1.34 +// 0x7FFFFFFF: if invalid system call.
1.35 +// -----------------------------------------------------------------------------
1.36 +//
1.37 +
1.38 +extern "C" {
1.39 +
1.40 +#define MAXPATHLEN 260 /* E32STD.H: KMaxFullName + 4 to avoid data loss */
1.41 +
1.42 +EXPORT_C int creat(const char* file, mode_t mode)
1.43 + {
1.44 + wchar_t _widename[MAXPATHLEN+1];
1.45 +
1.46 + if(!file)
1.47 + {
1.48 + errno = EFAULT ;
1.49 + return -1 ;//null file pointer
1.50 + }
1.51 +
1.52 + if ((size_t)-1 != mbstowcs(_widename, file, MAXPATHLEN))
1.53 + {
1.54 + return _open_r(&errno , _widename , O_CREAT | O_WRONLY | O_TRUNC , mode);
1.55 + }
1.56 + else
1.57 + {
1.58 + errno = EILSEQ;
1.59 + return -1; // Illegal Sequence of wide characters
1.60 + }
1.61 + }
1.62 +
1.63 +
1.64 +EXPORT_C int wcreat(const wchar_t* file, mode_t mode)
1.65 + {
1.66 + if (file)
1.67 + {
1.68 + return _wopen_r(&errno , file , O_CREAT | O_WRONLY | O_TRUNC , mode);
1.69 + }
1.70 + else
1.71 + {
1.72 + errno = EFAULT;
1.73 + return -1; //null file pointer
1.74 + }
1.75 + }
1.76 +}