File: iobuf_close.c

package info (click to toggle)
bglibs 2.04%2Bdfsg-8
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,468 kB
  • sloc: ansic: 15,821; perl: 674; sh: 63; makefile: 29
file content (24 lines) | stat: -rw-r--r-- 524 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <sys/types.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <unistd.h>
#include "iobuf.h"

/** Close an \c iobuf and deallocate the buffer. */
int iobuf_close(iobuf* io)
{
  int status;
  if (io->flags & IOBUF_NEEDSMUNMAP) {
    munmap(io->buffer, io->bufsize);
    io->buffer = 0;
  }
  else if (io->flags & IOBUF_NEEDSFREE) {
    free(io->buffer);
    io->buffer = 0;
  }
  status = 1;
  if ((io->flags & IOBUF_NEEDSCLOSE) && io->fd != -1)
    status = close(io->fd) != -1;
  io->fd = -1;
  return status;
}