Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

Linux System ProgrammingÔĶÁ±Ê¼ÇÖ® read(....)

¹ØÓÚread(...)·µ»ØÖµµÄÕýÈ·Åжϣºp30
File I/O µÄ read(...)º¯ÊýÓ÷¨£º
ÓÐÎÊÌâµÄ´úÂ룬ֻÅжϷµ»ØֵΪ-1µÄÇé¿ö¡£
unsigned long word;
ssize_t nr;
/* read a couple bytes into 'word' from 'fd' */
nr = read (fd, &word, sizeof (unsigned long));
if (nr == -1)
/* error */
Indeed, a call to read( ) can result in many possibilities:
• The call returns a value equal to len. All len read bytes are stored in buf. The
results are as intended.
• The call returns a value less than len, but greater than zero. The read bytes are
stored in buf. This can occur because a signal interrupted the read midway, an
error occurred in the middle of the read, more than zero, but less than len bytes’
worth of data was available, or EOF was reached before len bytes were read.
Reissuing the read (with correspondingly updated buf and len values) will read the
remaining bytes into the rest of the buffer, or indicate the cause of the problem.
• The call returns 0. This indicates EOF. There is nothing to read.
• The call blocks because no data is currently available. This won’t happen in nonblocking
mode.
• The call returns -1, and errno is set to EINTR. This indicates that a signal was
received before any bytes were read. The call can be reissued.
• The call returns -1, and errno is set to EAGAIN. This indicates that the read would
block because no data is currently available, and that the request should be reissued
later. This happens only in nonblocking mode.
• The call returns -1, and errno is set to a value other than EINTR or EAGAIN. This
indicates a more serious error.
ÕýÈ·×ö·¨£º
ssize_t ret;
while (len != 0 && (ret = read (fd, buf, len)) != 0) {
  if (ret == -1) {
    if (errno == EINTR)
    continue;
    perror ("read");
    break;
  }
  len -= ret;
  buf += ret;
}


Ïà¹ØÎĵµ£º

Linux³ÌÐòÉè¼Æ——ÓÃgetopt´¦ÀíÃüÁîÐвÎÊý

LinuxϺܶà³ÌÐòÉõÖÁÄÇЩ¾ßÓÐͼÐÎÓû§½çÃ棨graphical user interface£¬GUI£©µÄ³ÌÐò£¬¶¼ÄܽÓÊܺʹ¦ÀíÃüÁîÐÐÑ¡Ïî¡£¶ÔÓÚijЩ³ÌÐò£¬ÕâÊÇÓëÓû§½øÐн»»¥µÄÖ÷ÒªÊֶΡ£¾ßÓпɿ¿µÄ¸´ÔÓÃüÁîÐвÎÊý´¦Àí»úÖÆ£¬»áʹµÃÄúµÄÓ¦ÓóÌÐò¸üºÃ¡¢¸üÓÐÓá£getopt()ÊÇÒ»¸öרÃÅÉè¼ÆÀ´¼õÇáÃüÁîÐд¦Àí¸ºµ£µÄ¿âº¯Êý¡£
1¡¢ÃüÁîÐвÎÊý
ÃüÁîÐгÌÐòÉè¼Æ ......

LINUX½ø³Ì¹ÜÀí

1. ½ø³ÌÊÇʲô?
Ò»¸ö½ø³Ì¾ÍÊdzöÓÚÖ´ÐÐÆڵijÌÐò, °üÀ¨:¿ÉÖ´ÐгÌÐò´úÂë(´úÂë¶Î), ´ò¿ªµÄÎļþ, ¹ÒÆðµÄÐźÅ, ÄÚºËÄÚ²¿Êý¾Ý, ´¦ÀíÆ÷״̬, µØÖ·¿Õ¼ä, Ò»¸ö»ò¶à¸öÖ´ÐÐÏß³Ì, µ±È»»¹°üÀ¨ÓÃÀ´´æ·ÅÈ«¾Ö±äÁ¿µÄÊý¾Ý¶Î, µÈµÈ.
 
2. ʲôÊÇÏß³Ì?ËüºÍ½ø³ÌµÄ¹ØϵÊÇʲôÑùµÄ? Ïß³ÌÔÚLINUXÖоßÌåÊÇÔõôÑùʵÏÖµÄ?
ÊÇÔÚ½ø³ÌÖлµÄ¶ÔÏó ......

ShellµÄʹÓ×—linux¹¤³Ìʦ±Øѧ»ù´¡

Ô­µØÖ·£ºhttp://selftest.51cto.com/subread.php?sid=213
×Ô²â¼ò½é£º    
ShellÒ²½Ð×öÃüÁîÐнçÃ棬ËüÊÇUnix/ÀàUnix²Ù×÷ϵͳÏ´«Í³µÄÓû§ºÍ¼ÆËã»úµÄ½»»¥½çÃæ¡£Óû§Ö±½ÓÊäÈëÃüÁîÀ´Ö´Ðи÷ÖÖ¸÷ÑùµÄÈÎÎñ¡£µ±È»Î¢ÈíµÄWindows²Ù×÷ϵͳҲÌṩÁËÕâÑùµÄ¹¦ÄÜ£¬ËüÃÇÊÇWindows 9XϵÄcommand.com£¬ºÍ»ùÓÚWindows NTµÄ¸ ......

Linux Óû§²ãÈçºÎµ÷ÓýӿÚÉèÖüĴæÆ÷

ÏÂÃæµÄ´úÂë·ÖÎöÊǸù¾Ýlinux-2.6.17.14_stm22°æ±¾
#define STSYS_WriteRegDev32LE(Address_p, value)          writel((u32)value, (void*)Address_p)
ÔÚinclude/asm-sh/io.h
#define writel(v,a) ({__raw_writel((v),(a));mb();})
#define __raw_write(v,a)  __writ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ