/*******************************************************************************1* Copyright (c) 1998, 2014 IBM Corp. and others2*3* This program and the accompanying materials are made available under4* the terms of the Eclipse Public License 2.0 which accompanies this5* distribution and is available at https://www.eclipse.org/legal/epl-2.0/6* or the Apache License, Version 2.0 which accompanies this distribution and7* is available at https://www.apache.org/licenses/LICENSE-2.0.8*9* This Source Code may also be made available under the following10* Secondary Licenses when the conditions for such availability set11* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU12* General Public License, version 2 with the GNU Classpath13* Exception [1] and GNU General Public License, version 2 with the14* OpenJDK Assembly Exception [2].15*16* [1] https://www.gnu.org/software/classpath/license.html17* [2] http://openjdk.java.net/legal/assembly-exception.html18*19* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception20*******************************************************************************/2122#include "iohelp.h"23#include "jclglob.h"24#include "jclprots.h"252627/**28* This will convert all separators to the proper platform separator29* and remove duplicates on non POSIX platforms.30*/31void ioh_convertToPlatform(char *path)32{33char * pathIndex;34int length = (int)strlen(path);3536/* Convert all separators to the same type */37pathIndex = path;38while (*pathIndex != '\0') {39if ((*pathIndex == '\\' || *pathIndex == '/') && (*pathIndex != jclSeparator))40*pathIndex = jclSeparator;41pathIndex++;42}4344/* Remove duplicate separators */45if (jclSeparator == '/') return; /* Do not do POSIX platforms */4647/* Remove duplicate initial separators */48pathIndex = path;49while ((*pathIndex != '\0') && (*pathIndex == jclSeparator)) {50pathIndex++;51}52if ((pathIndex > path) && (length > (pathIndex - path)) && (*(pathIndex + 1) == ':')) {53/* For Example '////c:/_*' ('_' added to silence compiler warning) */54int newlen = (int)(length - (pathIndex - path));55memmove(path, pathIndex, newlen);56path[newlen] = '\0';57} else {58if ((pathIndex - path > 3) && (length > (pathIndex - path))) {59/* For Example '////serverName/_*' ('_' added to silence compiler warning) */60int newlen = (int)(length - (pathIndex - path) + 2);61memmove(path, pathIndex - 2, newlen);62path[newlen] = '\0';63}64}65/* This will have to handle extra \'s but currently doesn't */6667}686970