Did anyone mention that a directory must have the x flag for a user to search (ls) it? Or what about the -R flag, which recursively gives subdirectories the same permissions?

And, you people are only thinking user-level. It's also a system call:
#include <sys/types.h>
#include <sys/stat.h>

int chmod( const char *path, mode_t mode );
int fchmod( int fd, mode_t mode );
fchmod does a chmod on an open file descriptor. Here are the flags for "mode", done with an or, as usual:
S_ISUID		setuid
S_ISGID		setgid
S_ISVTX		sticky bit
S_IRUSR		owner read
S_IWUSR		owner write
S_IXUSR		owner execute/search
S_IRGRP		group read
S_IWGRP		group write
S_IXGRP		group execute/search
S_IROTH		other read
S_IWOTH		other write
S_IXOTH		other execute/search