asm_abort.c revision a38998e815ccde5d90ff0800c31da255eb3430d3
1b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Abort operations on the assembler context, free all resources.
2a38998e815ccde5d90ff0800c31da255eb3430d3Ulrich Drepper   Copyright (C) 2002, 2005 Red Hat, Inc.
3b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper   Written by Ulrich Drepper <drepper@redhat.com>, 2002.
4b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
5b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper   This program is Open Source software; you can redistribute it and/or
6b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper   modify it under the terms of the Open Software License version 1.0 as
7b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper   published by the Open Source Initiative.
8b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
9b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper   You should have received a copy of the Open Software License along
10b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper   with this program; if not, you may obtain a copy of the Open Software
11b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper   License version 1.0 from http://www.opensource.org/licenses/osl.php or
12b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper   by writing the Open Source Initiative c/o Lawrence Rosen, Esq.,
13b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper   3001 King Ranch Road, Ukiah, CA 95482.   */
14b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
15b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#ifdef HAVE_CONFIG_H
16b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper# include <config.h>
17b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#endif
18b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
19b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#include <stdlib.h>
20b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#include <unistd.h>
21b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
22b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#include <libasmP.h>
23b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#include <libelf.h>
24b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
25b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
26b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperint
27b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperasm_abort (ctx)
28b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper     AsmCtx_t *ctx;
29b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper{
30b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  if (ctx == NULL)
31b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper    /* Something went wrong earlier.  */
32b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper    return -1;
33b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
34b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  if (likely (! ctx->textp))
35b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper    /* First free the ELF file.  We don't care about the result.  */
36b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper    (void) elf_end (ctx->out.elf);
37b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
38b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  /* Now close the temporary file and remove it.  */
39a38998e815ccde5d90ff0800c31da255eb3430d3Ulrich Drepper  if (ctx->fd != -1)
40a38998e815ccde5d90ff0800c31da255eb3430d3Ulrich Drepper    (void) unlink (ctx->tmp_fname);
41b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
42b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  /* Free the resources.  */
43b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  __libasm_finictx (ctx);
44b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
45b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  return 0;
46b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper}
47