#! /usr/bin/env python3

from sys import argv

errno = {
    '0': 'Success',
    '1': 'TooBig',
    '2': 'Acces',
    '3': 'Addrinuse',
    '4': 'Addrnotavail',
    '5': 'Afnosupport',
    '6': 'Again',
    '7': 'Already',
    '8': 'Badf',
    '9': 'Badmsg',
    '10': 'Busy',
    '11': 'Canceled',
    '12': 'Child',
    '13': 'Connaborted',
    '14': 'Connrefused',
    '15': 'Connreset',
    '16': 'Deadlk',
    '17': 'Destaddrreq',
    '18': 'Dom',
    '19': 'Dquot',
    '20': 'Exist',
    '21': 'Fault',
    '22': 'Fbig',
    '23': 'Hostunreach',
    '24': 'Idrm',
    '25': 'Ilseq',
    '26': 'Inprogress',
    '27': 'Intr',
    '28': 'Inval',
    '29': 'Io',
    '30': 'Isconn',
    '31': 'Isdir',
    '32': 'Loop',
    '33': 'Mfile',
    '34': 'Mlink',
    '35': 'Msgsize',
    '36': 'Multihop',
    '37': 'Nametoolong',
    '38': 'Netdown',
    '39': 'Netreset',
    '40': 'Netunreach',
    '41': 'Nfile',
    '42': 'Nobufs',
    '43': 'Nodev',
    '44': 'Noent',
    '45': 'Noexec',
    '46': 'Nolck',
    '47': 'Nolink',
    '48': 'Nomem',
    '49': 'Nomsg',
    '50': 'Noprotoopt',
    '51': 'Nospc',
    '52': 'Nosys',
    '53': 'Notconn',
    '54': 'Notdir',
    '55': 'Notempty',
    '56': 'Notrecoverable',
    '57': 'Notsock',
    '58': 'Notsup',
    '59': 'Notty',
    '60': 'Nxio',
    '61': 'Overflow',
    '62': 'Ownerdead',
    '63': 'Perm',
    '64': 'Pipe',
    '65': 'Proto',
    '66': 'Protonosupport',
    '67': 'Prototype',
    '68': 'Range',
    '69': 'Rofs',
    '70': 'Spipe',
    '71': 'Srch',
    '72': 'Stale',
    '73': 'Timedout',
    '74': 'Txtbsy',
    '75': 'Xdev',
    '76': 'Notcapable',
}

desc = {
    'success': 'No error occurred. System call completed successfully.',
    'toobig': 'Argument list too long.',
    'acces': 'Permission denied.',
    'addrinuse': 'Address in use.',
    'addrnotavail': 'Address not available.',
    'afnosupport': 'Address family not supported.',
    'again': 'Resource unavailable, or operation would block.',
    'already': 'Connection already in progress.',
    'badf': 'Bad file descriptor.',
    'badmsg': 'Bad message.',
    'busy': 'Device or resource busy.',
    'canceled': 'Operation canceled.',
    'child': 'No child processes.',
    'connaborted': 'Connection aborted.',
    'connrefused': 'Connection refused.',
    'connreset': 'Connection reset.',
    'deadlk': 'Resource deadlock would occur.',
    'destaddrreq': 'Destination address required.',
    'dom': 'Mathematics argument out of domain of function.',
    'dquot': 'Reserved.',
    'exist': 'File exists.',
    'fault': 'Bad address.',
    'fbig': 'File too large.',
    'hostunreach': 'Host is unreachable.',
    'idrm': 'Identifier removed.',
    'ilseq': 'Illegal byte sequence.',
    'inprogress': 'Operation in progress.',
    'intr': 'Interrupted function.',
    'inval': 'Invalid argument.',
    'io': 'I/O error.',
    'isconn': 'Socket is connected.',
    'isdir': 'Is a directory.',
    'loop': 'Too many levels of symbolic links.',
    'mfile': 'File descriptor value too large.',
    'mlink': 'Too many links.',
    'msgsize': 'Message too large.',
    'multihop': 'Reserved.',
    'nametoolong': 'Filename too long.',
    'netdown': 'Network is down.',
    'netreset': 'Connection aborted by network.',
    'netunreach': 'Network unreachable.',
    'nfile': 'Too many files open in system.',
    'nobufs': 'No buffer space available.',
    'nodev': 'No such device.',
    'noent': 'No such file or directory.',
    'noexec': 'Executable file format error.',
    'nolck': 'No locks available.',
    'nolink': 'Reserved.',
    'nomem': 'Not enough space.',
    'nomsg': 'No message of the desired type.',
    'noprotoopt': 'Protocol not available.',
    'nospc': 'No space left on device.',
    'nosys': 'Function not supported.',
    'notconn': 'The socket is not connected.',
    'notdir': 'Not a directory or a symbolic link to a directory.',
    'notempty': 'Directory not empty.',
    'notrecoverable': 'State not recoverable.',
    'notsock': 'Not a socket.',
    'notsup': 'Not supported, or operation not supported on socket.',
    'notty': 'Inappropriate I/O control operation.',
    'nxio': 'No such device or address.',
    'overflow': 'Value too large to be stored in data type.',
    'ownerdead': 'Previous owner died.',
    'perm': 'Operation not permitted.',
    'pipe': 'Broken pipe.',
    'proto': 'Protocol error.',
    'protonosupport': 'Protocol not supported.',
    'prototype': 'Protocol wrong type for socket.',
    'range': 'Result too large.',
    'rofs': 'Read-only file system.',
    'spipe': 'Invalid seek.',
    'srch': 'No such process.',
    'stale': 'Reserved.',
    'timedout': 'Connection timed out.',
    'txtbsy': 'Text file busy.',
    'xdev': 'Cross-device link.',
    'notcapable': 'Extension: Capabilities insufficient.',
}

if __name__ == '__main__':
    if len(argv) == 1:
        print(f"Usage: {argv[0]} errno ...")
    else:
        for arg in argv[1:]:
            if arg in errno:
                print(f"{arg}: {errno[arg]} -- {desc[errno[arg].lower()]}")
            else:
                print(f"{arg}: ***UNKNOWN ERROR NUMBER***")
