![Symbian Developer Library](../../../../a_stock/images/mainheading.gif)
![]() |
![]() |
|
Interface status: | externallyDefinedApi |
typedef __clock_t clock_t;
Used for system times in clock ticks or CLOCKS_PER_SEC
Interface status: | externallyDefinedApi |
typedef __clockid_t clockid_t;
Used for clock ID type in the clock and timer functions.
Interface status: | externallyDefinedApi |
typedef __fsblkcnt_t fsblkcnt_t;
Used for file system block counts.
Interface status: | externallyDefinedApi |
typedef __fsfilcnt_t fsfilcnt_t;
Used for file system file counts.
Interface status: | externallyDefinedApi |
typedef __id_t id_t;
Used as a general identifier; can be used to contain at least a pid_t, uid_t, or gid_t.
Interface status: | externallyDefinedApi |
typedef __key_t key_t;
Used for XSI interprocess communication.
Interface status: | externallyDefinedApi |
typedef __segsz_t segsz_t;
segment size (in Pages)
Interface status: | externallyDefinedApi |
typedef __timer_t timer_t;
Used for timer ID returned by timer_create().
Interface status: | externallyDefinedApi |
typedef __u_register_t u_register_t;
register type
Interface status: | externallyDefinedApi |
typedef __useconds_t useconds_t;
Used for time in microseconds
Interface status: | externallyDefinedApi |
IMPORT_C int ftruncate(int, off_t);
|
|
Interface status: | externallyDefinedApi |
IMPORT_C off_t lseek(int, off_t, int);
The lseek system call repositions the offset of the file descriptor fildes to the argument offset according to the directive whence. The argument fildes must be an open file descriptor. The lseek system call repositions the file position pointer associated with the file descriptor fildes as follows: If whence is SEEK_SET, the offset is set to offset bytes. If whence is SEEK_CUR, the offset is set to its current location plus offset bytes. If whence is SEEK_END, the offset is set to the size of the file plus offset bytes. Some devices are incapable of seeking. The value of the pointer associated with such a device is undefined.
Note : lseek function allows the file offset to be set beyond the existing end-of-file, data in the seeked slot is undefined, and hence the read operation in seeked slot is undefined untill data is actually written into it. lseek beyond existing end-of-file increases the file size accordingly.
Errors:
The lseek system call will fail and the file position pointer will remain unchanged if: [EBADF] The fildes argument is not an open file descriptor. [EINVAL] The whence argument is not a proper value or the resulting file offset would be negative for a non-character special file. [EOVERFLOW] The resulting file offset would be a value which cannot be represented correctly in an object of type off_t(Not supported). [ESPIPE] The fildes argument is associated with a pipe, socket, or FIFO.
Examples:
/*
Detailed description : Example for lseek usage.
*/
# 787 "d:/EPOC/release/9.4/common/generic/openenv/core/include/unistd.dosc" 2
# 788 "d:/EPOC/release/9.4/common/generic/openenv/core/include/unistd.dosc" 2
# 789 "d:/EPOC/release/9.4/common/generic/openenv/core/include/unistd.dosc" 2
# 790 "d:/EPOC/release/9.4/common/generic/openenv/core/include/unistd.dosc" 2
int main()
{
int fd = 0;
fd = open("lseek.txt" , 0x0200 | 0x0002 , 0666);
if(lseek(fd , 0 , 0 ) < 0 ) {
printf("Lseek on file lseek.txt failed \n");
return -1;
}
printf("Lseek on lseek.txt passed ");
return 0;
}
Output
Lseek on lseek.txt passed
|
|
Interface status: | externallyDefinedApi |
IMPORT_C void* mmap(void *, size_t, int, int, int, off_t);
The mmap system call causes the pages starting at addr and continuing for at most len bytes to be mapped from the object described by fildes, starting at byte offset offset. If len is not a multiple of the pagesize, the mapped region may extend past the specified range. Any such extension beyond the end of the mapped object will be zero-filled.
If addr is non-zero, it is used as a hint to the system. (As a convenience to the system, the actual address of the region may differ from the address supplied). If addr is zero, an address will be selected by the system. The actual starting address of the region is returned. A successful mmap deletes any previous mapping in the allocated address range.
The protections (region accessibility) are specified in the prot argument by or'ing the following values:
PROT_READ Pages may be read.
PROT_WRITE Pages may be written.
PROT_EXEC Pages may be executed.
PROT_NONE This protection mode is currently not supported.
The flags argument specifies the type of the mapped object, mapping options and whether modifications made to the mapped copy of the page are private to the process or are to be shared with other references. Sharing, mapping type and options are specified in the flags argument by or'ing the following values:
MAP_PRIVATE Modifications are private.
MAP_SHARED Modifications are shared.
MAP_FIXED, MAP_FILE, MAP_ANON, MAP_HASSEMAPHORE, MAP_STACK, MAP_NOSYNC -- These flags are currently not supported.
The close system call does not unmap pages, see munmap for further information.
The current design does not allow a process to specify the location of swap space. In the future we may define an additional mapping type, MAP_SWAP, in which the file descriptor argument specifies a file or device to which swapping should be done.
Examples:
/* Detailed description : Example to create a mapped memory to a file region.
Precondition : None
/
#include <unistd.h>
#include <stdio.h>
#include <sys/mman.h>
#include <fcntl.h>
int main(void)
{
int fd = -1;
char* mapaddr;
int len = getpagesize();
int prot = PROT_WRITE | PROT_READ;
if((fd = open("C:\Test.txt", O_RDWR | O_CREAT, 0666) ) < 0){
printf("File open failed");
}
mapaddr = (char*)mmap((void*)0, len, prot, MAP_SHARED, fd, 0);
if(mapaddr == MAP_FAILED){
printf("mmap on file failed");
}
printf("mmap on file succeeded");
}
|
mprotect(const void *,size_t,int)
mprotect(const void *,size_t,int)
...msync(void *,size_t,int)
msync(void *,size_t,int)
The msync system call writes any modified pages back to the file system. If len ...munmap(void *,size_t)
munmap(void *,size_t)
...getpagesize(void)
getpagesize(void)
The getpagesize function returns the number of bytes in a page. Page granularity...Interface status: | externallyDefinedApi |
IMPORT_C int truncate(const char *, off_t);
The truncate system call causes the file named by file or referenced by filedesc to be truncated to length bytes in size. If the file was larger than this size, the extra data is lost. If the file was smaller than this size, it will be extended as if by writing bytes with the value zero. With ftruncate, the file must be open for writing.
Examples:
//example for truncate
#include<unistd.h>
#include<stdio.h>
#include <sys/stat.h>
int test_truncate()
{
int retVal, retVal2, retSize, retSize2;
struct stat buf;
ssize_t size;
char *buffer = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwx";
int fp = open("c:\test.txt", O_RDWR|O_CREAT);
size = write(fp,buffer,50);
close(fp);
retVal2 = stat("c:\test.txt", &buf );
if ( !retVal2 )
{
retSize = buf.st_size;
printf("Size before: %d", retSize);
retVal = truncate("c:\test.txt", retSize/2 );
}
else
{
printf("Failed");
}
retVal2 = stat( "c:\test.txt", &buf );
if ( !retVal2 )
{
retSize2 = buf.st_size;
if( retSize2 == (retSize/2 ) )
{
printf("\nSize after: %d\n", retSize2);
printf("Truncate passed");
return 0;
}
else
{
printf("Failed");
return -1;
}
}
else
{
printf("Failed");
return -1;
}
}
Output
Size before: 50
Size after: 25
Ttruncate Passed
Errors:
The truncate and ftruncate succeed unless: [EBADF] The filedesc argument is not a valid descriptor for a regular file. [EINVAL] The filedesc argument references to an object other than a file. [EINVAL] The filedesc descriptor is not open for writing.
Bugs:
These calls should be generalized to allow ranges of bytes in a file to be discarded. Use of truncate to extend a file is not portable.
|
|