os/ossrv/genericopenlibs/openenvcore/libc/src/creat.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 // 
    15 //
    16 
    17 
    18 #include <sys/errno.h>
    19 #include <stdlib.h>
    20 #include <fcntl.h>
    21 #include "sysreent.h"
    22 
    23 // -----------------------------------------------------------------------------
    24 // Creat  :  Function that stub which 
    25  
    26 // This function takes the system call number and that transforms
    27 // controll to the respective routines that performs the task 
    28 // requested .                                          
    29 // Returns: -1: if the requested task fails 
    30 //           0: if the requested task successfull
    31 //  0x7FFFFFFF: if invalid system call.                   
    32 // -----------------------------------------------------------------------------
    33 //
    34 
    35 extern "C" {
    36 
    37 #define	MAXPATHLEN	260	/* E32STD.H: KMaxFullName + 4 to avoid data loss */
    38 	
    39 EXPORT_C int creat(const char* file, mode_t mode)
    40 	{
    41 	wchar_t _widename[MAXPATHLEN+1];
    42 	
    43 	if(!file)
    44 		{
    45 		errno = EFAULT ;
    46 		return -1 ;//null file pointer
    47 		}
    48 
    49 	if ((size_t)-1 != mbstowcs(_widename, file, MAXPATHLEN))
    50 		{
    51 		return _open_r(&errno , _widename , O_CREAT | O_WRONLY | O_TRUNC , mode);  
    52 		}
    53 	else
    54 		{
    55 		errno = EILSEQ;
    56 		return -1;	// Illegal Sequence of wide characters
    57 		}
    58 	}
    59 
    60 
    61 EXPORT_C int wcreat(const wchar_t* file, mode_t mode)
    62 	{
    63 	if (file)
    64 		{
    65 		return _wopen_r(&errno , file , O_CREAT | O_WRONLY | O_TRUNC , mode);  
    66 		}
    67 	else
    68 		{
    69 		errno = EFAULT;
    70 		return -1;	//null file pointer
    71 		}
    72 	}
    73 }