Home | History | Annotate | Download | only in libebl
      1 /* Return section name.
      2    Copyright (C) 2001, 2002, 2004 Red Hat, Inc.
      3    Written by Ulrich Drepper <drepper (at) redhat.com>, 2001.
      4 
      5    This program is Open Source software; you can redistribute it and/or
      6    modify it under the terms of the Open Software License version 1.0 as
      7    published by the Open Source Initiative.
      8 
      9    You should have received a copy of the Open Software License along
     10    with this program; if not, you may obtain a copy of the Open Software
     11    License version 1.0 from http://www.opensource.org/licenses/osl.php or
     12    by writing the Open Source Initiative c/o Lawrence Rosen, Esq.,
     13    3001 King Ranch Road, Ukiah, CA 95482.   */
     14 
     15 #ifdef HAVE_CONFIG_H
     16 # include <config.h>
     17 #endif
     18 
     19 #include <stdio.h>
     20 #include <libeblP.h>
     21 
     22 
     23 const char *
     24 ebl_section_name (ebl, section, xsection, buf, len, scnnames, shnum)
     25      Ebl *ebl;
     26      int section;
     27      int xsection;
     28      char *buf;
     29      size_t len;
     30      const char *scnnames[];
     31      size_t shnum;
     32 {
     33   const char *res = ebl != NULL ? ebl->section_name (section, xsection,
     34 						     buf, len) : NULL;
     35 
     36   if (res == NULL)
     37     {
     38       if (section == SHN_UNDEF)
     39 	res = "UNDEF";
     40       else if (section == SHN_ABS)
     41 	res = "ABS";
     42       else if (section == SHN_COMMON)
     43 	res = "COMMON";
     44       else if (section == SHN_BEFORE)
     45 	res = "BEFORE";
     46       else if (section == SHN_AFTER)
     47 	res = "AFTER";
     48       else if ((section < SHN_LORESERVE || section == SHN_XINDEX)
     49 	       && (size_t) section < shnum)
     50 	{
     51 	  int idx = section != SHN_XINDEX ? section : xsection;
     52 
     53 	  if (scnnames != NULL)
     54 	    res = scnnames[idx];
     55 	  else
     56 	    {
     57 	      snprintf (buf, len, "%d", idx);
     58 	      res = buf;
     59 	    }
     60 	}
     61       else
     62 	{
     63 	  /* Handle OS-specific section names.  */
     64 	  if (section == SHN_XINDEX)
     65 	    snprintf (buf, len, "%s: %d", "XINDEX", xsection);
     66 	  else if (section >= SHN_LOOS && section <= SHN_HIOS)
     67 	    snprintf (buf, len, "LOOS+%x", section - SHN_LOOS);
     68 	  /* Handle processor-specific section names.  */
     69 	  else if (section >= SHN_LOPROC && section <= SHN_HIPROC)
     70 	    snprintf (buf, len, "LOPROC+%x", section - SHN_LOPROC);
     71 	  else if (section >= SHN_LORESERVE && section <= SHN_HIRESERVE)
     72 	    snprintf (buf, len, "LORESERVE+%x", section - SHN_LORESERVE);
     73 	  else
     74 	    snprintf (buf, len, "%s: %d", gettext ("<unknown>"), section);
     75 
     76 	  res = buf;
     77 	}
     78     }
     79 
     80   return res;
     81 }
     82