1 1.1.1.4 mrg /* Copyright (C) 2018-2024 Free Software Foundation, Inc. 2 1.1 mrg Contributed by Jakub Jelinek <jakub (at) redhat.com>. 3 1.1 mrg 4 1.1 mrg This file is part of the GNU Offloading and Multi Processing Library 5 1.1 mrg (libgomp). 6 1.1 mrg 7 1.1 mrg Libgomp is free software; you can redistribute it and/or modify it 8 1.1 mrg under the terms of the GNU General Public License as published by 9 1.1 mrg the Free Software Foundation; either version 3, or (at your option) 10 1.1 mrg any later version. 11 1.1 mrg 12 1.1 mrg Libgomp is distributed in the hope that it will be useful, but WITHOUT ANY 13 1.1 mrg WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 14 1.1 mrg FOR A PARTICULAR PURPOSE. See the GNU General Public License for 15 1.1 mrg more details. 16 1.1 mrg 17 1.1 mrg Under Section 7 of GPL version 3, you are granted additional 18 1.1 mrg permissions described in the GCC Runtime Library Exception, version 19 1.1 mrg 3.1, as published by the Free Software Foundation. 20 1.1 mrg 21 1.1 mrg You should have received a copy of the GNU General Public License and 22 1.1 mrg a copy of the GCC Runtime Library Exception along with this program; 23 1.1 mrg see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 24 1.1 mrg <http://www.gnu.org/licenses/>. */ 25 1.1 mrg 26 1.1 mrg #include "libgomp.h" 27 1.1 mrg #include <string.h> 28 1.1 mrg #include <stdio.h> 29 1.1 mrg #include <stdlib.h> 30 1.1 mrg #ifdef HAVE_UNISTD_H 31 1.1 mrg #include <unistd.h> 32 1.1 mrg #endif 33 1.1 mrg #ifdef HAVE_INTTYPES_H 34 1.1 mrg # include <inttypes.h> /* For PRIx64. */ 35 1.1 mrg #endif 36 1.1 mrg #define WIN32_LEAN_AND_MEAN 37 1.1 mrg #include <windows.h> 38 1.1 mrg #include <errno.h> 39 1.1 mrg 40 1.1 mrg static int 41 1.1 mrg gomp_gethostname (char *name, size_t len) 42 1.1 mrg { 43 1.1 mrg /* On Win9x GetComputerName fails if the input size is less 44 1.1 mrg than MAX_COMPUTERNAME_LENGTH + 1. */ 45 1.1 mrg char buffer[MAX_COMPUTERNAME_LENGTH + 1]; 46 1.1 mrg DWORD size = sizeof (buffer); 47 1.1 mrg int ret = 0; 48 1.1 mrg 49 1.1 mrg if (!GetComputerName (buffer, &size)) 50 1.1 mrg return -1; 51 1.1 mrg 52 1.1 mrg if ((size = strlen (buffer) + 1) > len) 53 1.1 mrg { 54 1.1 mrg errno = EINVAL; 55 1.1 mrg /* Truncate as per POSIX spec. We do not NUL-terminate. */ 56 1.1 mrg size = len; 57 1.1 mrg ret = -1; 58 1.1 mrg } 59 1.1 mrg memcpy (name, buffer, (size_t) size); 60 1.1 mrg 61 1.1 mrg return ret; 62 1.1 mrg } 63 1.1 mrg 64 1.1 mrg #undef gethostname 65 1.1 mrg #define gethostname gomp_gethostname 66 1.1 mrg #define HAVE_GETHOSTNAME 1 67 1.1 mrg 68 1.1 mrg #include "../../affinity-fmt.c" 69