Remove unneeded tls_get_curthread() call.
[dragonfly.git] / lib / libdisk / blocks.c
1 /*
2  * ----------------------------------------------------------------------------
3  * "THE BEER-WARE LICENSE" (Revision 42):
4  * <phk@login.dknet.dk> wrote this file.  As long as you retain this notice you
5  * can do whatever you want with this stuff. If we meet some day, and you think
6  * this stuff is worth it, you can buy me a beer in return.   Poul-Henning Kamp
7  * ----------------------------------------------------------------------------
8  *
9  * $FreeBSD: src/lib/libdisk/blocks.c,v 1.7.2.3 2001/05/13 21:01:37 jkh Exp $
10  * $DragonFly: src/lib/libdisk/Attic/blocks.c,v 1.2 2003/06/17 04:26:49 dillon Exp $
11  *
12  */
13
14 #include <stdio.h>
15 #include <stdlib.h>
16 #include <unistd.h>
17 #include "libdisk.h"
18
19 void *
20 read_block(int fd, daddr_t block, u_long sector_size)
21 {
22         void *foo;
23
24         foo = malloc(sector_size);
25         if (!foo)
26                 return NULL;
27         if (-1 == lseek(fd, (off_t)block * sector_size, SEEK_SET)) {
28                 free (foo);
29                 return NULL;
30         }
31         if (sector_size != read(fd, foo, sector_size)) {
32                 free (foo);
33                 return NULL;
34         }
35         return foo;
36 }
37
38 int
39 write_block(int fd, daddr_t block, void *foo, u_long sector_size)
40 {
41         if (-1 == lseek(fd, (off_t)block * sector_size, SEEK_SET))
42                 return -1;
43         if (sector_size != write(fd, foo, sector_size))
44                 return -1;
45         return 0;
46 }