#include <sys/types.h>
#include <dirent.h>
#include <sys/time.h> 
#include <unistd.h>
#include <sys/stat.h>
#include <errno.h>
#include <stdlib.h>
#include <fcntl.h>
#include <string.h>
#include <sys/socket.h>

#define NODEFINE
#include <u.h>
#include <libc.h>
#include <fcall.h>
#include "fd.h"

int
pm_close(int fd)
{
	int ret;
	File *f;
	
	if((f = pm_lockfile(fd, 0)) == nil){
		if(pm_debug & PmDebugFd)
			pm_fprint(2, "pm_close %d: %s\n", fd);
		return -1;
	}
	ret = pm_closefile(f);
	if(pm_debug & PmDebugFd){
		if(ret < 0)
			pm_fprint(2, "pm_close %d: pm_closefile: %r\n", fd);
		else
			pm_fprint(2, "pm_close %d success\n", fd);
	}
	return ret;
}
