libansilove

Library for converting ANSI, ASCII, and other formats to PNG
Log | Files | Refs | README | LICENSE

clean.c (671B)


      1 /*
      2  * clean.c
      3  * libansilove 1.3.1
      4  * https://www.ansilove.org
      5  *
      6  * Copyright (c) 2011-2022 Stefan Vogt, Brian Cassidy, and Frederic Cambus
      7  * All rights reserved.
      8  *
      9  * libansilove is licensed under the BSD 2-Clause license.
     10  * See LICENSE file for details.
     11  *
     12  * SPDX-License-Identifier: BSD-2-Clause
     13  */
     14 
     15 #include <sys/mman.h>
     16 
     17 #include <stddef.h>
     18 #include "ansilove.h"
     19 #include "gd.h"
     20 
     21 int
     22 ansilove_clean(struct ansilove_ctx *ctx)
     23 {
     24 	if (ctx == NULL)
     25 		return -1;
     26 
     27 	if (ctx->png.buffer != NULL)
     28 		gdFree(ctx->png.buffer);
     29 
     30 	if (ctx->buffer != MAP_FAILED)
     31 		(void)munmap(ctx->buffer, ctx->maplen);
     32 
     33 	ctx->maplen = ctx->length = 0;
     34 	ctx->png.length = 0;
     35 
     36 	return 0;
     37 }