⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mem_write.c

📁 LINUX内核编程的一些程序例子
💻 C
字号:
/** @file mem_write.c * * @author marco corvi <marco_corvi@geocities.com> * @date   mar 2003 * * \brief write test for the mem_tty driver * */ #include <stdio.h>      // printf#include <stdlib.h>     // exit#include <sys/types.h>  // open#include <sys/stat.h>   // open#include <fcntl.h>      // open#include <unistd.h>     // read close sleep#include <errno.h>      // errnoint main( int argc, char ** argv ){  int fd;  char ch;  int i;  char * str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";  int len;  len = 0;  while ( str[len] ) len++;  fprintf(stderr, "mem_write: string %s len %d\n", str, len);  fd = open( argv[1], O_WRONLY | O_NDELAY );  if ( fd < 0 ) {    fprintf(stderr, "Error: unable to open %s (errno %d)\n", argv[1], errno);    exit( 1 );  }  for (i=0; i<10; i++) {    if ( write( fd, str, len ) <= 0) {      perror( "write str error");      break;    }    ch = '\n';    if ( write( fd, &ch, 1 ) <= 0) {      perror( "write \'\\n\' error");      break;    }    printf("Written string nr. %d\n", i);    sleep( 1 );  }  close( fd );  exit( 0 );}

⌨️ 快捷键说明

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