From: Michal Nazarewicz
> On Wed, Jan 29 2014, Robert Baldyga wrote:
> > + /* open endpoint files */
>
> ep_path = malloc(strlen(argv[1]) + 4 /* "/ep#" */ + 1 /* '\0' */);
> if (!ep_path) {
> perror("malloc");
> return 1;
> }
>
> At this point you could get away with sprintf.
>
> > + snprintf(ep_path, sizeof(ep_path), "%s/ep0", argv[1]);
> > + ep0 = open(ep_path, O_RDWR);
Or use openat().
(Getting the directory fd open with the correct permissions is left
as an exercise to the application by the writers of the standard.
You really need O_RDONLY | O_EXEC, but I think that is illegal and
linux may not allow O_EXEC for directories.
It ought to be possible to open a directory in a manner that excludes
the 'search' permissions needed for openat().)
David