Skip to content

Instantly share code, notes, and snippets.

@bwhitman
Created August 17, 2011 01:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bwhitman/1150608 to your computer and use it in GitHub Desktop.
Save bwhitman/1150608 to your computer and use it in GitHub Desktop.
Lion printf insanity
// DVLib.c gets very noisy when you do startWithSize here.. with "hack" printf that will get in the way of our cgi JPG binary output
// so we have to "mute" stdout temporarily via dup and freopen. first we save off stdout
int fd;
fpos_t pos;
fflush(stdout);
fgetpos(stdout, &pos);
fd = dup(fileno(stdout));
// now we redirect stdout to /dev/null
freopen("/dev/null", "w", stdout);
// right here it gets noisy
[camera startWithSize:NSMakeSize(640, 480)];
// and now we need to reset stdout back to normal
fflush(stdout);
dup2(fd, fileno(stdout));
close(fd);
clearerr(stdout);
fsetpos(stdout, &pos);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment