Miscellaneous Data


Back to page 1 . . . Forward to page 3


getpos and setpos

If you are using the routines fgetpos and fsetpos and notice that they aren't working correctly, it might be because you have mixed fileno calls with FILE * calls in the same program. Here is an example:


FILE * infile; int in_no; long count; char buf[100]; int err; off_t pos; infile = fopen("foo", "r"); /* FILE */ in_no = fileno(infile); /* Read 100 bytes */ count = 100; read(in_no, &buf, count); /* fileno */ /* Go back 10 bytes */ err = fgetpos(infile, &pos); /* FILE */ pos -= 10; err = fsetpos(infile, &pos); /* FILE */ /* And read some more */ count = 100; read(in_no, &buf, count); /* fileno */


It is surprising (and perhaps frustrating) that you cannot mix the two types of calls. The reason it's frustrating is that neither set of calls allows all types of operations to be performed. For example, there is no FILE * version of ioctl, and no fileno version of fsetpos (lseek is different because it has a more complicated interface).

In the example above, the second read will not re-read 10 bytes from the end of the first read plus 90 new bytes, but will instead read 100 new bytes.

The reason is that the read call has a buffer and its own file position pointer which is not updated by the fsetpos. More precisely: a fsetpos will only affect the file position of read if the fsetpos moves to a position outside the block that is currently buffered by read, and calls to read do not cause any change to the pointer that you get when you do a fgetpos.

If you want code like this to work, you have to either use all FILE * calls or all fileno calls. Here is the above code, fixed by using all FILE * calls:


FILE * infile; long count; char buf[100]; int err; fpos_t pos; infile = fopen("foo", "r"); /* FILE */ /* Read 100 bytes */ count = 100; fread(&buf, 1, count, infile); /* FILE */ /* Go back 10 bytes */ err = fgetpos(infile, &pos); /* FILE */ pos -= 10; err = fsetpos(infile, &pos); /* FILE */ /* And read some more */ count = 100; fread(&buf, 1, count, infile); /* FILE */


And here it is using all fileno calls:


int in_no; long count; char buf[100]; int err; off_t pos; in_no = open("foo", O_RDONLY); /* fileno */ /* Read 100 bytes */ count = 100; read(in_no, &buf, count); /* fileno */ /* Go back 10 bytes */ pos = lseek(in_no, 0, SEEK_CUR); /* fileno */ pos -= 10; lseek(in_no, pos, SEEK_SET); /* fileno */ /* And read some more */ count = 100; read(in_no, &buf, count); /* fileno */


Why are there two sets of routines? Each offers its own advantages:

  • The fileno routines are system routines, provided by the kernel. This makes them more efficient (less overhead) and available to all programmers regardless of what language you're using; also (for C programmers) their use allows you to be more independent of runtime libraries (the libc5 vs. glibc issue)
  • The FILE * routines are part of the C libraries, and as such offer more sophisticated actions, like reading a string, formatting input and output with fscanf and fprintf, etc.

Here is a fairly complete table of the routines, which should help you if you're used to one set of routines and decide you'd like to use the other.


Operation system call(s)
(using FILE *)
C library call(s)
(using fileno)
open/create/append open(2), creat(2) fopen(3), fdopen(3)
freopen(3)
close close(2) fclose(3)
read a block of data read(2) fread(3)
write a block of data write(2) fwrite(3)
flush written output fsync(2) fflush(3)
control buffering setvbuf(3)
get/set position lseek(2) fseek(3), ftell(3), rewind(3)
fgetpos(3), fsetpos(3)
set options fcntl(2), ioctl(2)
get directory info stat(2)
delete unlink(2)



South Park: Bigger, Longer and Uncut

Structure of the movie South Park: Bigger, Longer and Uncut as a 5-act play:


Act starts ends with
I 0:00:1x Lovely mountain town TV news satellite interview
II 0:12:24 Rehabilitation "Kyle's Mom is a bitch"
III 0:28:26 V-chip presentation "Tomorrow/La Resistance" medley
IV 0:47:05 Sadaam and Satan in bed The Mole dies
V 1:00:57 The execution Finale



Old British monetary system


pence written called usage and notes
0.25 1/4d farthing before Edward I, this was usually a penny cut into four pieces; farthing coin discontinued in 1956
0.5 1/2d half penny, ha'penny until Edward I this was usually a penny cut in half; ha'penny coin discontinued in 1971
1 1d penny penny coin discontinued in 1971
2 2d two pence, tuppence 2d coin was made briefly in the 18th century
3 3d three pence, threpney bit 3d coin was silver until 1944, then brass; discontinued in 1971
3.75 33/4d thruppence three farthing
4 4d groats coin made for large part of 19th century
4.5 41/2d fourpence-ha'penny
6 6d sixpence, tanner 6d coin discontinued in 1971
12 1s shilling, bob shilling coin discontinued in 1971
24 2/- or 2s two shillings, two bob, florin florin is 1/10 of a ppound, issued in 1849 to begin transition to decimal money system; florin coin discontinued in 1971
30 2s6d half crown coin discontinued in 1971
48 4s double florin coin made briefly in late 19th century
57 4s9d dollar re-struck Spanish or American dollar, worth 4s9d because of their weight in silver
60 5s crown
65 5s3d quarter guinea coin made up until George III
100 8/4 or 8s4d eight and fourpence
120 10s half sovereign,
ten bob
gold coin,
bank note
130 10s6d half-guinea coin made up until George III
240 £1 pound, sovereign, quid "quid" for "pound" in use 1688-present. "sovereign" for "coin valued at £1" in use 1817-present.
260 21s or £1 1s guinea "guinea" for "coin valued at 21s" in use 1717-1832. Used in auctions (buyer pays 7 guineas, seller gets 7 pounds, auctioneer keeps the difference of 7 shillings)
286 22s6d sovereign (obs.) "sovereign" for "coin valued at 22s" in use 1503-1660
480 £2 two pounds
520 £2 2s double guinea
1200 £5 five pounds

Sources:

http://home.clara.net/brianp/money.html

The Oxford English Dictionary



Sentence (in English) with all the Letters of the Alphabet

A sentence that uses each of the letters in its language is called a pangram.

In English, there are 26 letters. A 26-letter pangram using words listed in the Official Scrabble Players Dictionary is:

Cwm fjord bank glyphs vext quiz.

Its interpretation is roughly "Glyphs on the bank of the fjord leading into the mountain valley puzzled the eccentric."

vext is a rare but acceptable alternate form of vexed. Definition #2 of quiz is being used.

This is from a late 1970's issue of Games and Puzzles magazine. It also gave a few other less memorable solutions, possibly including these other 26-letter English pangrams:

Quartz glyph job vex'd cwm finks.

Vext cwm fly zing jabs Kurd qoph.

The fact that so many optimal pangrams exist in English results mainly from its highly complex and flexible grammar, and the borrowing of so many words from other languages.

Reader Mike Burt contributes this 26-letter sentence which is more reaable but does not quality under "official rules" because it uses a proper noun (name):

Nymph's quick waltz vex'd J.B. Frog.

Words with all the Vowels

The shortest is sequoia, with one each of the 5 vowels and only two consonants.

If you consider y to be a vowel, the shortest is a tie between audiometry and aureomycin each with 4 non-y consonants.

Because of the vowel frequencies in English, the UNIX command is most efficient if invoked as:


grep -i u /usr/dict/words | grep -i o | grep -i a | grep -i i | grep -i e


To find words with the vowels in order (A E I O U), use the command:

grep 'a.*e.*i.*o.*u' /usr/dict/words

which will find abstemious, facetious, adventitious and sacrilegious. Notice two of these have an extra i but the puzzle seldom requires a solution with exactly five vowels. All four are adjectives to which you can add -ly get a word with all six vowels in order. (There is at least one more, caesious (a noun), that is not in the standard /usr/dict/words).




Back to page 1 . . . Forward to page 3



Robert Munafo's home pages on VistaPages

Men Core Values


© 1996-2008 Robert P. Munafo. email me more info

This work is licensed under a Creative Commons Attribution 2.5 License. Details here

Back to my main page s.13