tail(1)
Plan9ã«ã¯tail(1)ã¯ãããã©ãhead(1)ããªããé é ãã¦å°»é ããï¼
æ¯è¨ã¯ããã¦ããã¦ãæè¿å¤æ¬å±ã§è¦ã¤ããããã¼ã¢ã³åã®ã½ã¼ã¹ã³ã¼ãæ¢æ¤ãã«tailã®å®è£ ã«mmapã使ã£ã¦ããã¨ãã話ãæ¸ããã¦ããã確ãã«ãå°»ããfseek(fseeko)ã§ã¡ã¾ã¡ã¾ããã®ã¼ãããå¹çãè¯ãããã ãPlan9ã¯mmapãæããªãã®ã§ãã©ããªå®è£ ã«ãªã£ã¦ããã®ã調ã¹ã¦ã¿ãã
ãªãã·ã§ã³ã«ãã£ã¦æåã¯å¤ãããããå°»ã®countè¡ã表示ã¯tail.c:keep()é¢æ°ã§å¦çãã¦ãããä½ã®ãã¨ã¯ãªããcountè¡åããããã¡ã«æ®ããªãããé ããreadããã¨ããããããåç´ãªå®è£ ã ã£ãã
/* * read whole file, keeping the tail * complexity is length(file)*length(tail). * could be linear. */ void keep(void) { int len = 0; long bufsiz = 0; char *buf = 0; int j, k, n; for(n=1; n;) { if(len+Bsize > bufsiz) { bufsiz += 2*Bsize; if(!(buf = realloc(buf, bufsiz+1))) fatal("out of space"); } for(; n && len<bufsiz; len+=n) n = tread(buf+len, bufsiz-len); if(count >= len) continue; if(units == CHARS) j = len - count; else { /* units == LINES */ j = buf[len-1]=='\n'? len-1: len; for(k=0; j>0; j--) if(buf[j-1] == '\n') if(++k >= count) break; } memmove(buf, buf+j, len-=j); } if(dir == REV) { if(len>0 && buf[len-1]!='\n') buf[len++] = '\n'; for(j=len-1 ; j>0; j--) if(buf[j-1] == '\n') { twrite(buf+j, len-j); if(--count <= 0) return; len = j; } } if(count > 0) twrite(buf, len); }
話ã¯æ»ã£ã¦ãããã¼ã¢ã³åã®ã½ã¼ã¹ã³ã¼ãæ¢æ¤ãã¯NetBSD 1.6ãç´ æã«ä½¿ã£ã¦ããããOpenBSDã®tailã¯NetBSDãmmapã使ã以åã«ãã©ã³ããããã®ããããfseekoã§ã¡ã¾ã¡ã¾ãã¡ã¤ã«ãã¤ã³ã¿ãåããã¦ãããmmapã使ããªãçç±ã¯ããã®ã ãããï¼
CVSãªãã¸ããªã¸ã®ãªã³ã¯ã示ããããã®å¦çãè¡ã£ã¦ããç®æã¯ãforward.c:rlines()ã
ã¾ããåæ¸ã§ã¯-fãªãã·ã§ã³ã®å®è£ ã調ã¹ã¦ãã¦ãselectã§ã¿ã¤ã ã¢ã¦ããããã¯ããã¯*1ãç´¹ä»ãã¦ããã®ã ããä»ã®å®è£ ã¯ã©ã¡ãã®BSDã§ããkqueue&keventã使ã£ã¦ããã
åç´ãªã³ãã³ãã§ããèªãã§ã¿ãã¨åå¼·ã«ãªããªãã
- ä½è : æ°·å±±ç´ å
- åºç社/ã¡ã¼ã«ã¼: ã¢ã¹ãã¼
- çºå£²æ¥: 2004/02
- ã¡ãã£ã¢: åè¡æ¬
- è³¼å ¥: 5人 ã¯ãªãã¯: 184å
- ãã®ååãå«ãããã° (29件) ãè¦ã
*1:sleep(3)ã使ãã¨å é¨ã§è¤æ°ã®ã·ã¹ãã ã³ã¼ã«ãå¼ã°ããããselect(2)ã ã¨ä¸åã§æ¸ãã