Поменять владельца файла или директории

Рейтинг: 1Ответов: 1Опубликовано: 02.05.2015

Как в c++ поменять права на файл или директорию? Знаю, есть функция chown, но она в виде аргументов принимает не строки, а id пользователя.

Ответы

▲ 1Принят

Попробуйте воспользоваться этими функциями для получения нужных вам идентификаторов:

  • getpwnam — function returns a pointer to a structure containing the broken-out fields of the record in the password database (e.g., the local password file /etc/passwd, NIS, and LDAP) that matches the username name.
  • getgrnam — function returns a pointer to a structure containing the broken-out fields of the record in the group database (e.g., the local group file /etc/group, NIS, and LDAP) that matches the group name name.