os/ossrv/genericopenlibs/openenvcore/libc/src/nice.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) 2005-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
// Name        : nice.cpp
sl@0
    15
// Part of     : LIBC
sl@0
    16
// Contains the source for fchdir
sl@0
    17
// Version     : 1.0
sl@0
    18
//
sl@0
    19
sl@0
    20
sl@0
    21
sl@0
    22
#include <sys/time.h>
sl@0
    23
#include <sys/resource.h>
sl@0
    24
#include <errno.h>
sl@0
    25
#include <e32std.h>
sl@0
    26
#include <e32const.h>
sl@0
    27
#include <unistd.h>
sl@0
    28
sl@0
    29
extern "C" {
sl@0
    30
sl@0
    31
/*
sl@0
    32
The function nice() increases or decreases the priority value by
sl@0
    33
adding the value 'incr' to the current priority.
sl@0
    34
It internally uses getpriority and setpriority to set the priority 
sl@0
    35
to new value.
sl@0
    36
It returns the new value of the priority, which shall be in the range 
sl@0
    37
of -15 to 19. -1 is a legitimate return value, so the user has to check 
sl@0
    38
the errno to be sure of failure.
sl@0
    39
*/
sl@0
    40
EXPORT_C int nice(int incr)
sl@0
    41
	{
sl@0
    42
	
sl@0
    43
	int retGetPri = -1;
sl@0
    44
	int retSetPri = -1;
sl@0
    45
	int retVal 	  = -1;
sl@0
    46
	
sl@0
    47
	if(((retGetPri = getpriority(PRIO_PROCESS, 0)) == -1) && (errno))
sl@0
    48
		{
sl@0
    49
		errno = ENOSYS;
sl@0
    50
		}
sl@0
    51
	else
sl@0
    52
		{
sl@0
    53
		retSetPri = setpriority(PRIO_PROCESS, 0, retGetPri + incr);
sl@0
    54
		if(!retSetPri)
sl@0
    55
			{
sl@0
    56
			retVal = 0;
sl@0
    57
			}
sl@0
    58
		}
sl@0
    59
	return retVal;
sl@0
    60
	}
sl@0
    61
sl@0
    62
} //extern "C"