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