Skip to content

Instantly share code, notes, and snippets.

@enkore
Created November 15, 2016 21:45
Show Gist options
  • Save enkore/ec4de5326b34716de1dee208e058d85d to your computer and use it in GitHub Desktop.
Save enkore/ec4de5326b34716de1dee208e058d85d to your computer and use it in GitHub Desktop.
SFTP open flags
static int
flags_from_portable(int pflags)
{
int flags = 0;
if ((pflags & SSH2_FXF_READ) &&
(pflags & SSH2_FXF_WRITE)) {
flags = O_RDWR;
} else if (pflags & SSH2_FXF_READ) {
flags = O_RDONLY;
} else if (pflags & SSH2_FXF_WRITE) {
flags = O_WRONLY;
}
if (pflags & SSH2_FXF_APPEND)
flags |= O_APPEND;
if (pflags & SSH2_FXF_CREAT)
flags |= O_CREAT;
if (pflags & SSH2_FXF_TRUNC)
flags |= O_TRUNC;
if (pflags & SSH2_FXF_EXCL)
flags |= O_EXCL;
return flags;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment