tell.gml

来自「开放源码的编译器open watcom 1.6.0版的源代码」· GML 代码 · 共 94 行

GML
94
字号
.func tell
#include <&iohdr>
&off_t tell( int &fd );
.ixfunc2 '&OsIo' &func
__int64 _telli64( int &fd );
.ixfunc2 '&OsIo' _telli64
.funcend
.*
.desc begin
The &func function reports the current file position at the operating
system level.
The
.arg &fd
value is the file &handle returned by a successful execution of the
.kw open
function.
.np
The returned value may be used in conjunction with the
.kw lseek
function to reset the current file position.
.np
The _&func.i64 function is similar to the &func function but returns a
64-bit file position.
This value may be used in conjunction with the
.kw _lseeki64
function to reset the current file position.
.desc end
.*
.return begin
If an error occurs in &func, (&minus.1L) is returned.
.np
If an error occurs in _&func.i64, (&minus.1I64) is returned.
.np
.im errnoref
.np
Otherwise, the current file position is returned in a system-dependent
manner.
A value of 0 indicates the start of the file.
.return end
.*
.see begin
.im seeioos tell
.see end
.*
.exmp begin
#include <stdio.h>
#include <sys&pc.stat.h>
#include <&iohdr>
#include <fcntl.h>

char buffer[]
        = { "A text record to be written" };
.exmp break
void main( void )
{
    int &fd;
    int size_written;

    /* open a file for output             */
    /* replace existing file if it exists */
    &fd = open( "file",
.if '&machsys' eq 'QNX' .do begin
                O_WRONLY | O_CREAT | O_TRUNC,
.do end
.el .do begin
                O_WRONLY | O_CREAT | O_TRUNC | O_TEXT,
.do end
                S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP );
.exmp break
    if( &fd != -1 ) {

        /* print file position */
        printf( "%ld\n", tell( &fd ) );

        /* write the text */
        size_written = write( &fd, buffer,
                              sizeof( buffer ) );

        /* print file position */
        printf( "%ld\n", tell( &fd ) );

        /* close the file */
        close( &fd );
    }
}
.exmp output
0
28
.exmp end
.*
.class WATCOM
.*
.system

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?