import struct


def unpack_fp(fmt, fp, increment=True):
    """Unpacks a structure from a file, increment the position if set.
    """

    if increment:
        return struct.unpack(fmt, fp.read(struct.calcsize(fmt)))
    else:
        pos = fp.tell()
        ret = struct.unpack(fmt, fp.read(struct.calcsize(fmt)))
        fp.seek(pos)
        return ret