mrtginfo.c
上传用户:lukesailor
上传日期:2007-01-04
资源大小:27k
文件大小:1k
- /* $Id: ls.c,v 1.6 1997/10/07 18:02:34 agulbra Exp $ */
- #include <stdio.h>
- #include <stdlib.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <fcntl.h>
- #include <string.h>
- #include <ctype.h>
- #include "ftpd.h"
- char * uptime( void )
- {
- char buf[1025];
- int f;
- int r;
- unsigned long u;
- f = open( "/proc/uptime", O_RDONLY );
- if ( f < 0 )
- return "?";
- r = read( f, buf, 1024 );
- if ( r <= 0 )
- return "?";
- close( f );
- u = strtoul( buf, NULL, 10 );
- sprintf( buf, "%d days, %d:%02d:%02d", u/86400, u/3600%24, u/60%60, u%60 );
- return strdup( buf );
- }
- char * name( void )
- {
- char buf[1025];
- int f;
- int r;
- f = open( "/proc/sys/kernel/hostname", O_RDONLY );
- if ( f < 0 )
- return "?";
- r = read( f, buf, 1024 );
- if ( r <= 0 )
- return "?";
- close( f );
- buf[r] = ' ';
- while( r && isspace( buf[r-1] ) )
- buf[--r] = ' ';
- return strdup( buf );
- }
- int main( int argc, char ** argv )
- {
- int d = daemons();
- printf( "%dn%dn%sn%sn", d, d, uptime(), name() );
- }