1 /* Add string to a section.
2 Copyright (C) 2002 Red Hat, Inc.
3 This file is part of elfutils.
4 Written by Ulrich Drepper <drepper@redhat.com>, 2002.
6 This file is free software; you can redistribute it and/or modify
7 it under the terms of either
9 * the GNU Lesser General Public License as published by the Free
10 Software Foundation; either version 3 of the License, or (at
11 your option) any later version
15 * the GNU General Public License as published by the Free
16 Software Foundation; either version 2 of the License, or (at
17 your option) any later version
19 or both in parallel, as here.
21 elfutils is distributed in the hope that it will be useful, but
22 WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24 General Public License for more details.
26 You should have received copies of the GNU General Public License and
27 the GNU Lesser General Public License along with this program. If
28 not, see <http://www.gnu.org/licenses/>. */
41 /* Add zero terminated string STR of size LEN to (sub)section ASMSCN. */
43 asm_addstrz (asmscn, str, len)
51 if (unlikely (asmscn->type == SHT_NOBITS))
57 __libasm_seterrno (ASM_E_TYPE);
65 for (cnt = 0; cnt < len; ++cnt)
68 __libasm_seterrno (ASM_E_TYPE);
75 len = strlen (str) + 1;
77 if (unlikely (asmscn->ctx->textp))
85 fputs ("\t.string\t\"", asmscn->ctx->out.file);
90 fputs ("\\000", asmscn->ctx->out.file);
91 else if (! isascii (*str))
92 fprintf (asmscn->ctx->out.file, "\\%03o",
93 (unsigned int) *((unsigned char *)str));
94 else if (*str == '\\')
95 fputs ("\\\\", asmscn->ctx->out.file);
96 else if (*str == '\n')
98 fputs ("\\n\"", asmscn->ctx->out.file);
102 fputc (*str, asmscn->ctx->out.file);
106 while (--len > 0 && (len > 1 || *str != '\0'));
109 fputs ("\"\n", asmscn->ctx->out.file);
113 /* Make sure there is enough room. */
114 if (__libasm_ensure_section_space (asmscn, len) != 0)
117 /* Copy the string. */
118 memcpy (&asmscn->content->data[asmscn->content->len], str, len);
120 /* Adjust the pointer in the data buffer. */
121 asmscn->content->len += len;
123 /* Increment the offset in the (sub)section. */
124 asmscn->offset += len;