/* Return a file descriptor for the apm_bios device, or -1 if there is an * error. Is this method secure? Should we make the device in /dev * instead of /tmp? * * apenwarr 2001/05/11: just throw out the weird temporary device file stuff. * It was only for ancient kernel versions anyway. */ int apm_open(void) { int fd; apm_info i; if (access(APM_PROC, R_OK) || apm_read(&i) == 1) return -1; if (i.driver_version[0] >= '1') { if ((fd = open(APM_DEVICE, O_RDWR)) < 0) { /* Try to create it. This is reasonable * for backward compatibility. */ if (mknod(APM_DEVICE, S_IFCHR | S_IRUSR | S_IWUSR, apm_dev())) { unlink(APM_DEVICE); return -1; } fd = open(APM_DEVICE, O_RDWR); } return fd; } return -1; }
/* * Return a file descriptor for the apm_bios device, or -1 if there is an * error. * * apenwarr 2001/05/11: just throw out the weird temporary device file stuff. * It was only for ancient kernel versions anyway. * alexamici 2001/12/14: remove the redundant check for kernel apm support. * Now apm_open() triggers the auto-load of the apm module. */ int apm_open(void) { int fd; if ((fd = open(APM_DEVICE, O_RDWR)) < 0) { /* * Try to create it. This is reasonable * for backward compatibility. */ if (mknod(APM_DEVICE, S_IFCHR | S_IRUSR | S_IWUSR, apm_dev())) { unlink(APM_DEVICE); return -1; } fd = open(APM_DEVICE, O_RDWR); } return fd; }