<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def which(name):
 """ Returns the full path to executable in path matching provided name. `name` String value. Returns string or ``None``. """


    # we were given a filename, return it if it's executable
    if os.path.dirname(name) != '':
        if not os.path.isdir(name) and os.access(name, os.X_OK):
            return name
        else:
            return None

    # fetch PATH env var and split
    path_val = os.environ.get('PATH', None) or os.defpath

    # return the first match in the paths
    for path in path_val.split(os.pathsep):
        filename = os.path.join(path, name)

        if os.access(filename, os.X_OK):
            return filename

    return None