3261N/A#!/usr/bin/python
3261N/A#
3261N/A# CDDL HEADER START
3261N/A#
3261N/A# The contents of this file are subject to the terms of the
3261N/A# Common Development and Distribution License (the "License").
3261N/A# You may not use this file except in compliance with the License.
3261N/A#
3261N/A# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
3261N/A# or http://www.opensolaris.org/os/licensing.
3261N/A# See the License for the specific language governing permissions
3261N/A# and limitations under the License.
3261N/A#
3261N/A# When distributing Covered Code, include this CDDL HEADER in each
3261N/A# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
3261N/A# If applicable, add the following below this CDDL HEADER, with the
3261N/A# fields enclosed by brackets "[]" replaced with your own identifying
3261N/A# information: Portions Copyright [yyyy] [name of copyright owner]
3261N/A#
3261N/A# CDDL HEADER END
3261N/A#
3261N/A
3261N/A#
3339N/A# Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
3261N/A#
3261N/A
3261N/Afrom __future__ import unicode_literals
3270N/Aimport os
3261N/Aimport six
3261N/Afrom pkg._syscallat import lib, ffi
3339N/Afrom pkg.misc import force_bytes
3261N/A
3261N/A
3261N/Adef mkdirat(fd, path, mode):
3261N/A """Invoke mkdirat(2)."""
3261N/A
3261N/A if not isinstance(fd, int):
3261N/A raise TypeError("fd must be int type")
3261N/A if not isinstance(path, six.string_types):
3261N/A raise TypeError("path must be a string")
3261N/A if not isinstance(mode, int):
3261N/A raise TypeError("mode must be int type")
3261N/A
3339N/A rv = lib.mkdirat(fd, force_bytes(path), mode)
3261N/A if rv != 0:
3270N/A raise OSError(ffi.errno, os.strerror(ffi.errno), path)
3261N/A
3261N/A
3261N/Adef openat(fildes, path, oflag, mode):
3261N/A """Invoke openat(2)."""
3261N/A
3261N/A if not isinstance(fildes, int):
3261N/A raise TypeError("fildes must be int type")
3261N/A if not isinstance(path, six.string_types):
3261N/A raise TypeError("path must be a string")
3261N/A if not isinstance(oflag, int):
3261N/A raise TypeError("oflag must be int type")
3261N/A if not isinstance(mode, int):
3261N/A raise TypeError("mode must be int type")
3261N/A
3339N/A rv = lib.openat(fildes, force_bytes(path), oflag, mode)
3261N/A if rv < 0:
3270N/A raise OSError(ffi.errno, os.strerror(ffi.errno), path)
3261N/A return rv
3261N/A
3261N/A
3261N/Adef renameat(fromfd, old, tofd, new):
3261N/A """Invoke renameat(2)."""
3261N/A
3261N/A if not isinstance(fromfd, int):
3261N/A raise TypeError("fromfd must be int type")
3261N/A if not isinstance(old, six.string_types):
3261N/A raise TypeError("old must be a string")
3261N/A if not isinstance(tofd, int):
3261N/A raise TypeError("tofd must be int type")
3261N/A if not isinstance(new, six.string_types):
3261N/A raise TypeError("new must be a string")
3261N/A
3339N/A rv = lib.renameat(fromfd, force_bytes(old), tofd, force_bytes(new))
3261N/A if rv != 0:
3270N/A raise OSError(ffi.errno, os.strerror(ffi.errno), old)
3261N/A
3261N/A
3261N/Adef unlinkat(dirfd, path, flag):
3261N/A """Invoke unlinkat(2)."""
3261N/A
3261N/A if not isinstance(dirfd, int):
3261N/A raise TypeError("dirfd must be int type")
3261N/A if not isinstance(path, six.string_types):
3261N/A raise TypeError("path must be a string")
3261N/A if not isinstance(flag, int):
3261N/A raise TypeError("flag must be int type")
3261N/A
3339N/A rv = lib.unlinkat(dirfd, force_bytes(path), flag)
3261N/A if rv < 0:
3270N/A raise OSError(ffi.errno, os.strerror(ffi.errno), path)